qat.core.Topology
- class qat.core.Topology(is_directed=False, nbqbits=None, **kwargs)
Simple higher-level wrapper for the serializable Topology class.
- Parameters
topology (ThriftTopology, optional) – serializable object describing the topology
is_directed (bool, optional) – set the topology directed or undirected (used if your topology is Custom). If your topology is undirected, any qubit of a pair is either a control or a target qubit, otherwise, only one qubit of the pair is the control qubit. The topology is, by default, undirected
type (
TopologyType
, optional) – type of the topology (All to All, LNN or Custom)graph (dict<int, list<int>>, optional) – graph describing the topology (required iff the topology is Custom). Any key of this dictionary corresponds to the index of a control qubit and each linked value corresponds to indexes of qubits which can be target of this control qubit
nbqbits (int, optional) – number of qubits
- add_edge(qb1, qb2)
Update connectivity between qubits. The topology will be set to CUSTOM (if needed). Use this method if a two qubits gate can be applied between qubits of indexes
qb1
andqb2
Note
If your topology is directed, the first argument is the control qubit.
- Parameters
qb1 (int) – index of the first qubit
qb2 (int) – index of the second qubit
- dump(fname)
Dumps the Toplogy inside a file in binary format.
- Parameters
fname (str) – the file name
- classmethod from_bytes(data: bytes)
Builds a topology from raw bytes object
- static from_nx(nx_graph, vmap=None)
Builds a Topology object from a networkx Graph
- Parameters
nx_graph (networkx.Graph) – a networkx Graph
vmap (optional, dict) – if set, the dictionary is update with a map that maps graph nodes to qubit indexes
- classmethod from_thrift(tobject, init_none=False)
Builds a Topology object from a thrift topology object
- static load(fname)
Loads a Topology from a file.
- Parameters
fname (str) – the file name
- Returns
- property nbqbits
Getter of nbqbits of a topology object
- set_nbqbits()
A helper method that set the nbqbits of a custom topology, used by the HardwareSpecs to fix the number of qubits of a custom topology
- to_nx(nqbits=None)
Cast the Topology object into a networkx graph.
- Parameters
nqbits (optional, int) – if specified, the number of qubits
- Returns
a networkx graph
- Return type
nx.Graph