def test_default_init(self): """Tests that the device is properly initialized.""" dev = CirqDevice(3, 100) assert dev.num_wires == 3 assert dev.shots == 100
def test_default_init(self, num_wires, shots): """Tests that the device is properly initialized.""" dev = CirqDevice(num_wires, shots) assert dev.num_wires == num_wires assert dev.shots == shots
def test_default_init_of_qubits(self): """Tests the default initialization of CirqDevice.qubits.""" dev = CirqDevice(3, 100, False) assert len(dev.qubits) == 3 assert dev.qubits[0] == cirq.LineQubit(0) assert dev.qubits[1] == cirq.LineQubit(1) assert dev.qubits[2] == cirq.LineQubit(2)
def test_outer_init_of_qubits_unordered(self): """Tests that giving qubits as parameters to CirqDevice works when the qubits are not ordered consistently with Cirq's convention.""" qubits = [ cirq.GridQubit(0, 1), cirq.GridQubit(1, 0), cirq.GridQubit(0, 0), cirq.GridQubit(1, 1), ] dev = CirqDevice(4, 100, False, qubits=qubits) assert len(dev.qubits) == 4 assert dev.qubits == sorted(qubits)
def test_outer_init_of_qubits_error(self): """Tests that giving the wrong number of qubits as parameters to CirqDevice raises an error.""" qubits = [ cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0), cirq.GridQubit(1, 1), ] with pytest.raises( qml.DeviceError, match="The number of given qubits and the specified number of wires have to match", ): dev = CirqDevice(3, 100, False, qubits=qubits)
def test_outer_init_of_qubits(self): """Tests that giving qubits as parameters to CirqDevice works.""" qubits = [ cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0), cirq.GridQubit(1, 1), ] dev = CirqDevice(4, 100, qubits=qubits) assert len(dev.qubits) == 4 assert dev.qubits[0] == cirq.GridQubit(0, 0) assert dev.qubits[1] == cirq.GridQubit(0, 1) assert dev.qubits[2] == cirq.GridQubit(1, 0) assert dev.qubits[3] == cirq.GridQubit(1, 1)
def test_to_paulistring_single_gate(): with patch.multiple(CirqDevice, __abstractmethods__=set()): device = CirqDevice(2, shots=1, analytic=True) result = device.to_paulistring(qml.PauliX(0)) assert result == cirq.X(cirq.LineQubit(0))
def cirq_device_3_wires(shots): """A mock instance of the abstract Device class""" with patch.multiple(CirqDevice, __abstractmethods__=set()): yield CirqDevice(3, shots=shots, analytic=True)
def cirq_device_1_wire(shots): """A mock instance of the abstract Device class""" with patch.multiple(CirqDevice, __abstractmethods__=set()): yield CirqDevice(1, shots=shots)
def test_to_paulistring_sanity_check(): with patch.multiple(CirqDevice, __abstractmethods__=set()): device = CirqDevice(2, shots=None) result = device.to_paulistring(qml.PauliX(0) @ qml.PauliZ(1)) assert result == cirq.X(cirq.LineQubit(0)) * cirq.Z(cirq.LineQubit(1))