def test_xmon_device_eq(): eq = EqualsTester() eq.make_equality_pair(lambda: square_device(3, 3)) eq.make_equality_pair(lambda: square_device(3, 3, holes=[XmonQubit(1, 1)])) eq.make_equality_pair(lambda: XmonDevice(Duration( nanos=1), Duration(nanos=2), Duration(nanos=3), [])) eq.make_equality_pair(lambda: XmonDevice(Duration( nanos=1), Duration(nanos=1), Duration(nanos=1), []))
def square_device(width, height, holes=()): ns = Duration(nanos=1) return XmonDevice(measurement_duration=ns, exp_w_duration=2 * ns, exp_11_duration=3 * ns, qubits=[ XmonQubit(x, y) for x in range(width) for y in range(height) if XmonQubit(x, y) not in holes ])
def test_greedy_method_calls_greedy_search(): q00 = XmonQubit(0, 0) q01 = XmonQubit(0, 1) q03 = XmonQubit(0, 3) device = XmonDevice(Duration(nanos=0), Duration(nanos=0), Duration(nanos=0), qubits=[q00, q01, q03]) method = greedy.GreedySequenceSearchMethod() with mock.patch.object(method, 'place_line') as place_line: sequences = [[q00, q01]] place_line.return_value = sequences assert place_on_device(device, method) == sequences place_line.assert_called_once_with(device)
def xmon_to_arc(xmon: XmonDevice) -> Architecture: """Generates a :math:`\\mathrm{t|ket}\\rangle` :py:class:`Architecture` object for a Cirq :py:class:`XmonDevice` . :param xmon: The device to convert :return: The corresponding :math:`\\mathrm{t|ket}\\rangle` :py:class:`Architecture` """ nodes = len(xmon.qubits) indexed_qubits = _sort_row_col(xmon.qubits) pairs = [] for qb in indexed_qubits: neighbours = xmon.neighbors_of(qb) #filter only higher index neighbours to avoid double counting edges forward_neighbours = filter( lambda x: indexed_qubits.index(x) > indexed_qubits.index(qb), neighbours) for x in forward_neighbours: pairs.append((indexed_qubits.index(qb), indexed_qubits.index(x))) return Architecture(pairs, nodes)
def process_characterisation(xmon: XmonDevice) -> dict: """Generates a tket dictionary containing device characteristics for a Cirq :py:class:`XmonDevice`. :param xmon: The device to convert :return: A dictionary containing device characteristics """ qb_map = {q: Node("q", q.row, q.col) for q in xmon.qubits} indexed_qubits = _sort_row_col(xmon.qubits) coupling_map = [] for qb in indexed_qubits: neighbours = xmon.neighbors_of(qb) for x in neighbours: coupling_map.append((qb_map[qb], qb_map[x])) arc = Architecture(coupling_map) node_ers_dict = {} link_ers_dict = {} for qb in xmon.qubits: error_cont = QubitErrorContainer({OpType.PhasedX, OpType.Rz}) error_cont.add_error((OpType.PhasedX, 0.0)) error_cont.add_error((OpType.Rz, 0.0)) node_ers_dict[qb_map[qb]] = error_cont for a, b in coupling_map: error_cont = QubitErrorContainer({OpType.CZ}) error_cont.add_error((OpType.CZ, 0.0)) link_ers_dict[(a, b)] = error_cont link_ers_dict[(b, a)] = error_cont characterisation = dict() characterisation["NodeErrors"] = node_ers_dict characterisation["EdgeErrors"] = link_ers_dict characterisation["Architecture"] = arc return characterisation
def _create_device(qubits: Iterable[GridQubit]) -> XmonDevice: return XmonDevice(Duration(nanos=0), Duration(nanos=0), Duration(nanos=0), qubits)
def _create_device(qubits: Iterable[XmonQubit]): return XmonDevice(Duration(nanos=0), Duration(nanos=0), Duration(nanos=0), qubits)