def __init__(self, include_additional_controlled_ops: bool = True): gate_families = [ cirq.ParallelGateFamily(cirq.H), cirq.ParallelGateFamily(cirq.PhasedXPowGate), cirq.ParallelGateFamily(cirq.XPowGate), cirq.ParallelGateFamily(cirq.YPowGate), cirq.ParallelGateFamily(cirq.ZPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CZPowGate), cirq.IdentityGate, cirq.MeasurementGate, ] self.include_additional_controlled_ops = include_additional_controlled_ops if self.include_additional_controlled_ops: gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CNotPowGate)) gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CCNotPowGate)) gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CCZPowGate)) # Call cirq.Gateset __init__ which is our grand-father inherited class # pylint doesn't like this so disable checks on this. # pylint: disable=bad-super-call super(cirq.neutral_atoms.NeutralAtomGateset, self).__init__(*gate_families, unroll_circuit_op=False)
def test_any_integer_power_gate_family(): with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'): cirq.AnyIntegerPowerGateFamily(gate=cirq.SingleQubitGate) with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'): cirq.AnyIntegerPowerGateFamily(gate=CustomXPowGate()) gate_family = cirq.AnyIntegerPowerGateFamily(CustomXPowGate) cirq.testing.assert_equivalent_repr(gate_family) assert CustomX in gate_family assert CustomX ** 2 in gate_family assert CustomX ** 1.5 not in gate_family assert CustomX ** sympy.Symbol('theta') not in gate_family assert 'CustomXPowGate' in gate_family.name assert '`g.exponent` is an integer' in gate_family.description
def __init__( self, control_radius: float, qubits: Sequence[Union[ThreeDQubit, GridQubit, LineQubit]]) -> None: """Initializes a device with some qubits. Args: control_radius: the maximum distance between qubits for a controlled gate. Distance is measured in units of the coordinates passed into the qubit constructor. qubits: Qubits on the device, identified by their x, y, z position. Must be of type ThreeDQubit, TwoDQubit, LineQubit or GridQubit. Raises: ValueError: if the wrong qubit type is provided or if invalid parameter is provided for control_radius.""" super().__init__(qubits) if not control_radius >= 0: raise ValueError( 'Control_radius needs to be a non-negative float.') if len(self.qubits) > 1: if control_radius > 3.0 * self.minimal_distance(): raise ValueError('Control_radius cannot be larger than 3 times' ' the minimal distance between qubits.') self.control_radius = control_radius self.gateset = PasqalGateset(include_additional_controlled_ops=False) self.controlled_gateset = cirq.Gateset( cirq.AnyIntegerPowerGateFamily(cirq.CZPowGate))
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, include_additional_controlled_ops: bool = True): gate_families = [ cirq.ParallelGateFamily(cirq.H), cirq.ParallelGateFamily(cirq.PhasedXPowGate), cirq.ParallelGateFamily(cirq.XPowGate), cirq.ParallelGateFamily(cirq.YPowGate), cirq.ParallelGateFamily(cirq.ZPowGate), cirq.AnyIntegerPowerGateFamily(cirq.CZPowGate), cirq.IdentityGate, cirq.MeasurementGate, ] self.include_additional_controlled_ops = include_additional_controlled_ops if self.include_additional_controlled_ops: gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CNotPowGate)) gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CCNotPowGate)) gate_families.append( cirq.AnyIntegerPowerGateFamily(cirq.CCZPowGate)) super().__init__(*gate_families, unroll_circuit_op=False)