From 0c8ba8bf24a233d45db3f94a477005618a81a4a3 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Wed, 13 Nov 2024 10:36:20 -0500 Subject: [PATCH] replace qubit_state_vector -> state_prep --- pennylane_cirq/cirq_device.py | 4 ++-- pennylane_cirq/simulator_device.py | 8 ++++---- tests/test_apply.py | 4 ++-- tests/test_mixed_simulator_device.py | 4 ++-- tests/test_simulator_device.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pennylane_cirq/cirq_device.py b/pennylane_cirq/cirq_device.py index 2e6303b..bdd7f75 100644 --- a/pennylane_cirq/cirq_device.py +++ b/pennylane_cirq/cirq_device.py @@ -239,7 +239,7 @@ def _apply_basis_state(self, basis_state_operation): raise NotImplementedError @abc.abstractmethod - def _apply_qubit_state_vector(self, qubit_state_vector_operation): + def _apply_state_prep(self, state_prep_operation): """Apply a state vector preparation. Args: @@ -284,7 +284,7 @@ def apply(self, operations, **kwargs): if operation.name == "BasisState": self._apply_basis_state(operation) elif operation.name == "StatePrep": - self._apply_qubit_state_vector(operation) + self._apply_state_prep(operation) else: self._apply_operation(operation) diff --git a/pennylane_cirq/simulator_device.py b/pennylane_cirq/simulator_device.py index f46c4dc..60b9079 100644 --- a/pennylane_cirq/simulator_device.py +++ b/pennylane_cirq/simulator_device.py @@ -91,12 +91,12 @@ def _apply_basis_state(self, basis_state_operation): self._initial_state = basis_state_operation.state_vector(wire_order=self.wires).flatten() - def _apply_qubit_state_vector(self, qubit_state_vector_operation): + def _apply_state_prep(self, state_prep_operation): # pylint: disable=missing-function-docstring if self.shots is not None: raise qml.DeviceError("The operator StatePrep is only supported in analytic mode.") - self._initial_state = qubit_state_vector_operation.state_vector( + self._initial_state = state_prep_operation.state_vector( wire_order=self.wires ).flatten() @@ -270,8 +270,8 @@ def _apply_basis_state(self, basis_state_operation): super()._apply_basis_state(basis_state_operation) self._initial_state = self._convert_to_density_matrix(self._initial_state) - def _apply_qubit_state_vector(self, qubit_state_vector_operation): - super()._apply_qubit_state_vector(qubit_state_vector_operation) + def _apply_state_prep(self, state_prep_operation): + super()._apply_state_prep(state_prep_operation) self._initial_state = self._convert_to_density_matrix(self._initial_state) def _convert_to_density_matrix(self, state_vec): diff --git a/tests/test_apply.py b/tests/test_apply.py index ffa596d..afe9ec8 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -106,7 +106,7 @@ def test_basis_state(self, shots, tol, state): expected[np.ravel_multi_index(state, [2] * 4)] = 1 assert np.allclose(res, expected, **tol) - def test_qubit_state_vector(self, init_state, shots, tol): + def test_state_prep(self, init_state, shots, tol): """Test PauliX application""" dev = SimulatorDevice(1, shots=shots) state = init_state(1) @@ -288,7 +288,7 @@ def test_identity_basis_state(self, shots, tol): expected = np.kron(expected, expected.conj()).reshape([16, 16]) assert np.allclose(res, expected, **tol) - def test_qubit_state_vector(self, init_state, shots, tol): + def test_state_prep(self, init_state, shots, tol): """Test PauliX application""" dev = MixedStateSimulatorDevice(1, shots=shots) state = init_state(1) diff --git a/tests/test_mixed_simulator_device.py b/tests/test_mixed_simulator_device.py index 45bf5a5..9eaa050 100644 --- a/tests/test_mixed_simulator_device.py +++ b/tests/test_mixed_simulator_device.py @@ -445,7 +445,7 @@ def test_basis_state_not_at_beginning_error(self, simulator_device_1_wire): ): simulator_device_1_wire.apply([qml.PauliX(0), qml.BasisState(np.array([0]), wires=[0])]) - def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire): + def test_state_prep_not_at_beginning_error(self, simulator_device_1_wire): """Tests that application of StatePrep raises an error if is not the first operation.""" @@ -474,7 +474,7 @@ def test_basis_state_not_analytic_error(self, simulator_device_1_wire): ): simulator_device_1_wire.apply([qml.BasisState(np.array([0]), wires=[0])]) - def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire): + def test_state_prep_not_analytic_error(self, simulator_device_1_wire): """Tests that application of StatePrep raises an error if the device is not in analytic mode.""" diff --git a/tests/test_simulator_device.py b/tests/test_simulator_device.py index 633b9a1..ef056d7 100644 --- a/tests/test_simulator_device.py +++ b/tests/test_simulator_device.py @@ -471,7 +471,7 @@ def test_basis_state_not_at_beginning_error(self, simulator_device_1_wire): ): simulator_device_1_wire.apply([qml.PauliX(0), qml.BasisState(np.array([0]), wires=[0])]) - def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire): + def test_state_prep_not_at_beginning_error(self, simulator_device_1_wire): """Tests that application of StatePrep raises an error if is not the first operation.""" @@ -500,7 +500,7 @@ def test_basis_state_not_analytic_error(self, simulator_device_1_wire): ): simulator_device_1_wire.apply([qml.BasisState(np.array([0]), wires=[0])]) - def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire): + def test_state_prep_not_analytic_error(self, simulator_device_1_wire): """Tests that application of StatePrep raises an error if the device is not in analytic mode."""