Skip to content

Commit e94c315

Browse files
Delete references to the removed QubitStateVector class (#203)
* remove qsv and update changelog * ran black * Update CHANGELOG.md Co-authored-by: Mudit Pandey <[email protected]> * Update pennylane_cirq/cirq_device.py Co-authored-by: Mudit Pandey <[email protected]> * replace qubit_state_vector -> state_prep * ran black --------- Co-authored-by: Mudit Pandey <[email protected]>
1 parent 86740c4 commit e94c315

File tree

8 files changed

+25
-27
lines changed

8 files changed

+25
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### Breaking changes 💔
88

9+
* The ``qml.QubitStateVector`` template has been removed. Instead, use :class:`~pennylane.StatePrep`.
10+
[(#203)](https://github.com/PennyLaneAI/pennylane-cirq/pull/203)
11+
912
### Deprecations 👋
1013

1114
### Documentation 📝
@@ -16,6 +19,8 @@
1619

1720
This release contains contributions from (in alphabetical order):
1821

22+
Andrija Paurevic
23+
1924
---
2025
# Release 0.39.0
2126

doc/devices/qsim.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ more qubits.
122122
For state preparation qsim relies on decomposing ``BasisState`` into a set of
123123
`PauliX
124124
<https://pennylane.readthedocs.io/en/stable/code/api/pennylane.PauliX.html>`__
125-
gates and `QubitStateVector
126-
<https://pennylane.readthedocs.io/en/stable/code/api/pennylane.QubitStateVector.html>`__
125+
gates and `StatePrep
126+
<https://pennylane.readthedocs.io/en/stable/code/api/pennylane.StatePrep.html>`__
127127
via `Möttönen state preparation
128128
<https://pennylane.readthedocs.io/en/stable/code/api/pennylane.templates.state_preparations.MottonenStatePreparation.html>`__.

pennylane_cirq/cirq_device.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def __init__(self, wires, shots, qubits=None):
118118
_base_operation_map = {
119119
**{f"Pow({k})": v for k, v in _pow_operation_map.items()},
120120
"BasisState": None,
121-
"QubitStateVector": None,
122121
"StatePrep": None,
123122
"QubitUnitary": CirqOperation(cirq.MatrixGate),
124123
"PauliX": CirqOperation(lambda: cirq.X),
@@ -240,11 +239,11 @@ def _apply_basis_state(self, basis_state_operation):
240239
raise NotImplementedError
241240

242241
@abc.abstractmethod
243-
def _apply_qubit_state_vector(self, qubit_state_vector_operation):
242+
def _apply_state_prep(self, state_prep_operation):
244243
"""Apply a state vector preparation.
245244
246245
Args:
247-
qubit_state_vector_operation (pennylane.QubitStateVector): the QubitStateVector operation instance that shall be applied
246+
state_prep_operation (pennylane.StatePrep): the StatePrep operation instance that shall be applied
248247
249248
Raises:
250249
NotImplementedError: when not implemented in the subclass
@@ -277,15 +276,15 @@ def apply(self, operations, **kwargs):
277276
rotations = kwargs.pop("rotations", [])
278277

279278
for i, operation in enumerate(operations):
280-
if i > 0 and operation.name in {"BasisState", "QubitStateVector", "StatePrep"}:
279+
if i > 0 and operation.name in {"BasisState", "StatePrep"}:
281280
raise qml.DeviceError(
282281
f"The operation {operation.name} is only supported at the beginning of a circuit."
283282
)
284283

285284
if operation.name == "BasisState":
286285
self._apply_basis_state(operation)
287-
elif operation.name in {"StatePrep", "QubitStateVector"}:
288-
self._apply_qubit_state_vector(operation)
286+
elif operation.name == "StatePrep":
287+
self._apply_state_prep(operation)
289288
else:
290289
self._apply_operation(operation)
291290

pennylane_cirq/qsim_device.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def reset(self):
6767
def operations(self):
6868
# pylint: disable=missing-function-docstring
6969
return set(self._base_operation_map) - {
70-
"QubitStateVector",
7170
"StatePrep",
7271
"BasisState",
7372
"CRX",
@@ -129,7 +128,6 @@ def __init__(self, wires, qsimh_options, shots=None, qubits=None):
129128
def operations(self):
130129
# pylint: disable=missing-function-docstring
131130
return set(self._base_operation_map) - {
132-
"QubitStateVector",
133131
"StatePrep",
134132
"BasisState",
135133
"CRX",

pennylane_cirq/simulator_device.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,12 @@ def _apply_basis_state(self, basis_state_operation):
9191

9292
self._initial_state = basis_state_operation.state_vector(wire_order=self.wires).flatten()
9393

94-
def _apply_qubit_state_vector(self, qubit_state_vector_operation):
94+
def _apply_state_prep(self, state_prep_operation):
9595
# pylint: disable=missing-function-docstring
9696
if self.shots is not None:
97-
raise qml.DeviceError(
98-
"The operations StatePrep and QubitStateVector are only supported in analytic mode."
99-
)
97+
raise qml.DeviceError("The operator StatePrep is only supported in analytic mode.")
10098

101-
self._initial_state = qubit_state_vector_operation.state_vector(
102-
wire_order=self.wires
103-
).flatten()
99+
self._initial_state = state_prep_operation.state_vector(wire_order=self.wires).flatten()
104100

105101
def apply(self, operations, **kwargs):
106102
# pylint: disable=missing-function-docstring
@@ -272,8 +268,8 @@ def _apply_basis_state(self, basis_state_operation):
272268
super()._apply_basis_state(basis_state_operation)
273269
self._initial_state = self._convert_to_density_matrix(self._initial_state)
274270

275-
def _apply_qubit_state_vector(self, qubit_state_vector_operation):
276-
super()._apply_qubit_state_vector(qubit_state_vector_operation)
271+
def _apply_state_prep(self, state_prep_operation):
272+
super()._apply_state_prep(state_prep_operation)
277273
self._initial_state = self._convert_to_density_matrix(self._initial_state)
278274

279275
def _convert_to_density_matrix(self, state_vec):

tests/test_apply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_basis_state(self, shots, tol, state):
106106
expected[np.ravel_multi_index(state, [2] * 4)] = 1
107107
assert np.allclose(res, expected, **tol)
108108

109-
def test_qubit_state_vector(self, init_state, shots, tol):
109+
def test_state_prep(self, init_state, shots, tol):
110110
"""Test PauliX application"""
111111
dev = SimulatorDevice(1, shots=shots)
112112
state = init_state(1)
@@ -288,7 +288,7 @@ def test_identity_basis_state(self, shots, tol):
288288
expected = np.kron(expected, expected.conj()).reshape([16, 16])
289289
assert np.allclose(res, expected, **tol)
290290

291-
def test_qubit_state_vector(self, init_state, shots, tol):
291+
def test_state_prep(self, init_state, shots, tol):
292292
"""Test PauliX application"""
293293
dev = MixedStateSimulatorDevice(1, shots=shots)
294294
state = init_state(1)

tests/test_mixed_simulator_device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def test_basis_state_not_at_beginning_error(self, simulator_device_1_wire):
445445
):
446446
simulator_device_1_wire.apply([qml.PauliX(0), qml.BasisState(np.array([0]), wires=[0])])
447447

448-
def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire):
448+
def test_state_prep_not_at_beginning_error(self, simulator_device_1_wire):
449449
"""Tests that application of StatePrep raises an error if is not
450450
the first operation."""
451451

@@ -474,15 +474,15 @@ def test_basis_state_not_analytic_error(self, simulator_device_1_wire):
474474
):
475475
simulator_device_1_wire.apply([qml.BasisState(np.array([0]), wires=[0])])
476476

477-
def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire):
477+
def test_state_prep_not_analytic_error(self, simulator_device_1_wire):
478478
"""Tests that application of StatePrep raises an error if the device
479479
is not in analytic mode."""
480480

481481
simulator_device_1_wire.reset()
482482

483483
with pytest.raises(
484484
qml.DeviceError,
485-
match="The operations StatePrep and QubitStateVector are only supported in analytic mode.",
485+
match="The operator StatePrep is only supported in analytic mode.",
486486
):
487487
simulator_device_1_wire.apply([qml.StatePrep(np.array([0, 1]), wires=[0])])
488488

tests/test_simulator_device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def test_basis_state_not_at_beginning_error(self, simulator_device_1_wire):
471471
):
472472
simulator_device_1_wire.apply([qml.PauliX(0), qml.BasisState(np.array([0]), wires=[0])])
473473

474-
def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire):
474+
def test_state_prep_not_at_beginning_error(self, simulator_device_1_wire):
475475
"""Tests that application of StatePrep raises an error if is not
476476
the first operation."""
477477

@@ -500,15 +500,15 @@ def test_basis_state_not_analytic_error(self, simulator_device_1_wire):
500500
):
501501
simulator_device_1_wire.apply([qml.BasisState(np.array([0]), wires=[0])])
502502

503-
def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire):
503+
def test_state_prep_not_analytic_error(self, simulator_device_1_wire):
504504
"""Tests that application of StatePrep raises an error if the device
505505
is not in analytic mode."""
506506

507507
simulator_device_1_wire.reset()
508508

509509
with pytest.raises(
510510
qml.DeviceError,
511-
match="The operations StatePrep and QubitStateVector are only supported in analytic mode.",
511+
match="The operator StatePrep is only supported in analytic mode.",
512512
):
513513
simulator_device_1_wire.apply([qml.StatePrep(np.array([0, 1]), wires=[0])])
514514

0 commit comments

Comments
 (0)