def test_metadata(): qubits = cirq.LineQubit.range(4) graph = nx.star_graph(3) metadata = cirq.DeviceMetadata(qubits, graph) assert metadata.qubit_set == frozenset(qubits) assert metadata.nx_graph == graph metadata = cirq.DeviceMetadata() assert metadata.qubit_set is None assert metadata.nx_graph is None
def test_metadata_equality(): qubits = cirq.LineQubit.range(4) graph = nx.star_graph(3) graph2 = nx.star_graph(3) graph.add_edge(1, 2, directed=False) graph2.add_edge(1, 2, directed=True) eq = cirq.testing.EqualsTester() eq.add_equality_group(cirq.DeviceMetadata(qubits, graph)) eq.add_equality_group(cirq.DeviceMetadata(qubits, graph2)) eq.add_equality_group(cirq.DeviceMetadata(qubits[1:], graph))
def test_metadata_json_load_logic(): qubits = cirq.LineQubit.range(4) graph = nx.star_graph(3) metadata = cirq.DeviceMetadata(qubits, graph) str_rep = cirq.to_json(metadata) assert metadata == cirq.read_json(json_text=str_rep) qubits = None graph = None metadata = cirq.DeviceMetadata(qubits, graph) str_rep = cirq.to_json(metadata) output = cirq.read_json(json_text=str_rep) assert metadata == output
def __init__(self, qubits: Sequence[cirq.Qid]) -> None: """Initializes a device with some qubits. Args: qubits (NamedQubit): Qubits on the device, exclusively unrelated to a physical position. Raises: TypeError: If the wrong qubit type is provided. ValueError: If the number of qubits is greater than the devices maximum. """ if len(qubits) > 0: q_type = type(qubits[0]) for q in qubits: if not isinstance(q, self.supported_qubit_type): raise TypeError('Unsupported qubit type: {!r}. This device ' 'supports qubit types: {}'.format( q, self.supported_qubit_type)) if not type(q) is q_type: raise TypeError("All qubits must be of same type.") if len(qubits) > self.maximum_qubit_number: raise ValueError('Too many qubits. {} accepts at most {} ' 'qubits.'.format(type(self), self.maximum_qubit_number)) self.gateset = PasqalGateset() self.qubits = qubits self._metadata = cirq.DeviceMetadata( qubits, nx.from_edgelist([(a, b) for a in qubits for b in qubits if a != b]))
def __init__(self, qubits: Sequence[cirq.Qid]) -> None: """Initializes a device with some qubits. Args: qubits (NamedQubit): Qubits on the device, exclusively unrelated to a physical position. Raises: TypeError: If the wrong qubit type is provided. ValueError: If the number of qubits is greater than the devices maximum. """ if len(qubits) > 0: q_type = type(qubits[0]) for q in qubits: if not isinstance(q, self.supported_qubit_type): raise TypeError('Unsupported qubit type: {!r}. This device ' 'supports qubit types: {}'.format( q, self.supported_qubit_type)) if not type(q) is q_type: raise TypeError("All qubits must be of same type.") if len(qubits) > self.maximum_qubit_number: raise ValueError('Too many qubits. {} accepts at most {} ' 'qubits.'.format(type(self), self.maximum_qubit_number)) self.gateset = cirq.Gateset( cirq.ParallelGateFamily(cirq.H), cirq.ParallelGateFamily(cirq.PhasedXPowGate), cirq.ParallelGateFamily(cirq.XPowGate), cirq.ParallelGateFamily(cirq.YPowGate), cirq.ParallelGateFamily(cirq.ZPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CNotPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CCNotPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CZPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CCZPowGate), cirq.IdentityGate, cirq.MeasurementGate, unroll_circuit_op=False, accept_global_phase_op=False, ) self.qubits = qubits self._metadata = cirq.DeviceMetadata( qubits, nx.from_edgelist([(a, b) for a in qubits for b in qubits if a != b]))
def __init__(self, qubits: Union[Sequence[cirq.LineQubit], int], atol=1e-8): """Construct the device. Args: qubits: The qubits upon which this device acts or the number of qubits. If the number of qubits, then the qubits will be `cirq.LineQubit`s from 0 to this number minus one. atol: The absolute tolerance used for gate calculations and decompositions. """ if isinstance(qubits, int): self.qubits = frozenset(cirq.LineQubit.range(qubits)) else: self.qubits = frozenset(qubits) self.atol = atol self._metadata = cirq.DeviceMetadata(self.qubits, [(a, b) for a in self.qubits for b in self.qubits if a != b])
def metadata(self): return cirq.DeviceMetadata(self.qubits, None)