qubiter.device_specific.ChipCouplingsFitter module¶

class
qubiter.device_specific.ChipCouplingsFitter.
ChipCouplingsFitter
(file_prefix, num_qbits, c_to_tars, verbose=False)[source]¶ Bases:
object
Recall that an undirected graph G is defined as a pair of sets (V, E), where V is a set of vertices, and E, the edges, is a set of tuples (c, t), where c and t are in V. For undirected graphs, the order of c and t is ignored.
This class reads an English file in order to build a list of the CNots used in the file. The CNots in the list are specified as (c, t) tuples. Then the class builds an undirected graph, call it GE=(V_GE, E_GE) for Graph_English, from that CNots list. Then the class builds another graph, call it GP=(V_GP, E_GP) for Graph_Physical, from the c_to_tars describing the couplings of a particular chip. Then the class uses the python networkx function for finding “graph isomorphisms” between undirected graphs. The class attempts to find a map phi() from the vertices of GE to the vertices of GP, so that phi(x_GE) is a subset of x_GP with x=V, E. If the search for phi() succeeds, then phi induces a permutation map, call it bit_map: range(num_qbits)>range(num_qbits), bit_ge>bit_gp, of the qubits of the circuit from which GE was assembled. Under this permutation, the CNots of the permuted circuit are all allowed** by the chip constraint c_to_tars. In that sense, the map bit_map() is a “fit” to the chip couplings.
**except, some CNots may have to be reversed (control and target swapped) using Hadamards. These reversals can be performed with the class ForbiddenCNotExpander.
Variables: bit_map (list[int]) – bit_map[bit_ge] = bit_gp defines a map from the bits bit_ge of the graph GE to the bits bit_gp of the graph GP. 
__init__
(file_prefix, num_qbits, c_to_tars, verbose=False)[source]¶ Constructor
Parameters:  file_prefix (str) – file prefix of English file which is to be read to assemble a list of CNots used in the file.
 num_qbits (int) – Number of qubits used in English file with file prefix file_prefix. IMP: We assume that c_to_tars refers to a chip with num_qbits too. Both the English file and the chip must have the same number of qubits. This is no loss of generality. As long as the English file doesn’t mention qubit positions >= num_qbits, all you have to do to conform is to change the name of the English file so that it claims to pertain to num_qbits qubits.
 c_to_tars (dict[int, list[int]]) – a dictionary mapping j in range(num_qbits) to a list, possibly empty, of the physically allowed targets of qubit j, when j is the control of a CNOT.
 verbose (bool) –

static
draw_phys_and_eng_graphs
(file_prefix, num_qbits, c_to_tars)[source]¶ Draws the Physical and English undirected graphs. This is useful in case you want to try to use human pattern recognition to embed the English graph inside the Physical graph.
Parameters:  file_prefix (str) –
 num_qbits (int) –
 c_to_tars (dict[int, list[int]]) –
Returns: Return type: None

static
get_bit_map_from_c_to_tars
(num_qbits, old_cnots, c_to_tars, verbose=False)[source]¶ This function has as inputs old_cnot describing the CNots in an English file for a circuit with num_qbits qubits and c_to_tars describing the couplings of a chip with num_qbits qubits. The function returns a list bit_map of num_bit many ints that describes a permutation map mapping range(num_qbits)>range( num_qbits), bit_ge>bit_gp. Under this permutation, the CNots of the circuit described by the input English file are mapped into new CNots which are all allowed** by the chip couplings constraint c_to_tars.
** except their targets and controls may have to be reversed.
Parameters:  num_qbits (int) –
 old_cnots (tuple[tuple[int, int]]) –
 c_to_tars (dict[int, list[int]]) –
 verbose (bool) –
Returns: Return type: list[int]

static
get_cnots_in_file
(file_prefix, num_qbits, verbose=False)[source]¶ This function reads an English file with file prefix file_prefix pertaining to a circuit with num_bit many qubits. It returns a tuple of the CNots mentioned in the English file. The CNots are specified as tuples (c, t), where c is the control bit position and t is the target bit position.
Parameters:  file_prefix (str) –
 num_qbits (int) –
 verbose (bool) –
Returns: Return type: tuple[tuple[int, int]]
