diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml
index 01c8f21..ccb2459 100644
--- a/.github/workflows/format.yml
+++ b/.github/workflows/format.yml
@@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
- python-version: 3.8
+ python-version: 3.9
- name: Install dependencies
run: pip install black
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 12d2de9..c6de244 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- python-version: [3.8, 3.9, '3.10']
+ python-version: [3.9, '3.10', '3.11']
steps:
- name: Cancel Previous Runs
diff --git a/.readthedocs.yaml b/.readthedocs.yaml
index eba4993..513fa0a 100644
--- a/.readthedocs.yaml
+++ b/.readthedocs.yaml
@@ -19,11 +19,14 @@ formats:
# Optionally set the version of Python and requirements required to build your docs
python:
- version: 3.8
install:
- requirements: doc/requirements.txt
- method: pip
path: .
build:
- image: latest
\ No newline at end of file
+ os: ubuntu-22.04
+ tools:
+ python: "3.9"
+ apt_packages:
+ - graphviz
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a08691..1ee342d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,16 +6,24 @@
### Breaking changes 💔
+* Python 3.8 support is dropped and Python 3.11 support is added.
+ [(#126)](https://github.com/PennyLaneAI/pennylane-cirq/pull/146)
+
### Deprecations 👋
### Documentation 📝
### Bug fixes 🐛
+* The plugin is updated to take `qml.StatePrep` operators, the new name for `qml.QubitStateVector`.
+ [(#126)](https://github.com/PennyLaneAI/pennylane-cirq/pull/146)
+
### Contributors ✍️
This release contains contributions from (in alphabetical order):
+Christina Lee
+
---
# Release 0.31.0
diff --git a/README.rst b/README.rst
index 98fbea2..c68f205 100644
--- a/README.rst
+++ b/README.rst
@@ -57,7 +57,7 @@ Features
Installation
============
-This plugin requires Python version 3.8 or above, as well as PennyLane
+This plugin requires Python version 3.9 or above, as well as PennyLane
and Cirq. Installation of this plugin, as well as all dependencies, can be done using ``pip``:
.. code-block:: bash
@@ -76,7 +76,7 @@ Dependencies
PennyLane-Cirq requires the following libraries be installed:
-* `Python `__ >= 3.8
+* `Python `__ >= 3.9
as well as the following Python packages:
diff --git a/doc/requirements.txt b/doc/requirements.txt
index fe954a2..fbf32f0 100644
--- a/doc/requirements.txt
+++ b/doc/requirements.txt
@@ -58,7 +58,7 @@ pytz==2021.1
PyYAML==6.0
requests==2.27.1
retworkx==0.11.0
-scipy==1.7.3
+scipy==1.11.2
semantic-version==2.10
six==1.16.0
snowballstemmer==2.2.0
@@ -75,7 +75,7 @@ sympy==1.9
toml==0.10.2
tqdm==4.64.0
traitlets==5.1.0
-typing_extensions==3.10.0.0
+typing_extensions==4.2.0
urllib3==1.26.9
# Do not pin the following
pennylane-sphinx-theme
diff --git a/pennylane_cirq/cirq_device.py b/pennylane_cirq/cirq_device.py
index 41f6ff4..87bc621 100644
--- a/pennylane_cirq/cirq_device.py
+++ b/pennylane_cirq/cirq_device.py
@@ -118,6 +118,7 @@ def __init__(self, wires, shots, qubits=None):
**{f"Pow({k})": v for k, v in _pow_operation_map.items()},
"BasisState": None,
"QubitStateVector": None,
+ "StatePrep": None,
"QubitUnitary": CirqOperation(cirq.MatrixGate),
"PauliX": CirqOperation(lambda: cirq.X),
"PauliY": CirqOperation(lambda: cirq.Y),
@@ -271,14 +272,14 @@ def apply(self, operations, **kwargs):
rotations = kwargs.pop("rotations", [])
for i, operation in enumerate(operations):
- if i > 0 and operation.name in {"BasisState", "QubitStateVector"}:
+ if i > 0 and operation.name in {"BasisState", "QubitStateVector", "StatePrep"}:
raise qml.DeviceError(
f"The operation {operation.name} is only supported at the beginning of a circuit."
)
if operation.name == "BasisState":
self._apply_basis_state(operation)
- elif operation.name == "QubitStateVector":
+ elif operation.name in {"StatePrep", "QubitStateVector"}:
self._apply_qubit_state_vector(operation)
else:
self._apply_operation(operation)
diff --git a/pennylane_cirq/qsim_device.py b/pennylane_cirq/qsim_device.py
index f49cabd..3e18828 100644
--- a/pennylane_cirq/qsim_device.py
+++ b/pennylane_cirq/qsim_device.py
@@ -67,6 +67,7 @@ def operations(self):
# pylint: disable=missing-function-docstring
return set(self._base_operation_map) - {
"QubitStateVector",
+ "StatePrep",
"BasisState",
"CRX",
"CRY",
@@ -122,6 +123,7 @@ def operations(self):
# pylint: disable=missing-function-docstring
return set(self._base_operation_map) - {
"QubitStateVector",
+ "StatePrep",
"BasisState",
"CRX",
"CRY",
diff --git a/pennylane_cirq/simulator_device.py b/pennylane_cirq/simulator_device.py
index 66e1fcb..8494969 100644
--- a/pennylane_cirq/simulator_device.py
+++ b/pennylane_cirq/simulator_device.py
@@ -79,7 +79,7 @@ def reset(self):
def capabilities(self): # pylint: disable=missing-function-docstring
capabilities = super().capabilities().copy()
capabilities.update(
- returns_state=(self.shots is None) # State information is only set if obtaining shots
+ returns_state=self.shots is None # State information is only set if obtaining shots
)
return capabilities
@@ -94,7 +94,7 @@ def _apply_qubit_state_vector(self, qubit_state_vector_operation):
# pylint: disable=missing-function-docstring
if self.shots is not None:
raise qml.DeviceError(
- "The operation QubitStateVector is only supported in analytic mode."
+ "The operations StatePrep and QubitStateVector are only supported in analytic mode."
)
self._initial_state = qubit_state_vector_operation.state_vector(
@@ -240,7 +240,7 @@ def __init__(self, wires, shots=None, qubits=None):
def capabilities(self): # pylint: disable=missing-function-docstring
capabilities = super().capabilities().copy()
capabilities.update(
- returns_state=(self.shots is None) # State information is only set if obtaining shots
+ returns_state=self.shots is None # State information is only set if obtaining shots
)
return capabilities
diff --git a/setup.py b/setup.py
index d322b01..b3fe52d 100644
--- a/setup.py
+++ b/setup.py
@@ -62,9 +62,9 @@
"Programming Language :: Python",
# Make sure to specify here the versions of Python supported
"Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Physics",
]
diff --git a/tests/test_apply.py b/tests/test_apply.py
index ddd5d2e..ffa596d 100644
--- a/tests/test_apply.py
+++ b/tests/test_apply.py
@@ -112,7 +112,7 @@ def test_qubit_state_vector(self, init_state, shots, tol):
state = init_state(1)
with mimic_execution_for_apply(dev):
- dev.apply([qml.QubitStateVector(state, wires=[0])])
+ dev.apply([qml.StatePrep(state, wires=[0])])
res = dev._state
expected = state
@@ -127,7 +127,7 @@ def test_single_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0]),
+ qml.StatePrep(state, wires=[0]),
qml.__getattribute__(name)(wires=[0]),
]
)
@@ -146,7 +146,7 @@ def test_single_qubit_parameters(self, init_state, shots, name, func, theta, tol
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0]),
+ qml.StatePrep(state, wires=[0]),
qml.__getattribute__(name)(theta, wires=[0]),
]
)
@@ -165,7 +165,7 @@ def test_rotation(self, init_state, shots, tol):
c = -0.654
with mimic_execution_for_apply(dev):
- dev.apply([qml.QubitStateVector(state, wires=[0]), qml.Rot(a, b, c, wires=[0])])
+ dev.apply([qml.StatePrep(state, wires=[0]), qml.Rot(a, b, c, wires=[0])])
res = dev._state
expected = rot(a, b, c) @ state
@@ -180,7 +180,7 @@ def test_two_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1]),
+ qml.StatePrep(state, wires=[0, 1]),
qml.__getattribute__(name)(wires=[0, 1]),
]
)
@@ -198,7 +198,7 @@ def test_qubit_unitary(self, init_state, shots, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=list(range(N))),
+ qml.StatePrep(state, wires=list(range(N))),
qml.QubitUnitary(mat, wires=list(range(N))),
]
)
@@ -225,7 +225,7 @@ def test_three_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1, 2]),
+ qml.StatePrep(state, wires=[0, 1, 2]),
qml.__getattribute__(name)(wires=[0, 1, 2]),
]
)
@@ -244,7 +244,7 @@ def test_two_qubits_parameters(self, init_state, shots, name, func, theta, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1]),
+ qml.StatePrep(state, wires=[0, 1]),
qml.__getattribute__(name)(theta, wires=[0, 1]),
]
)
@@ -294,7 +294,7 @@ def test_qubit_state_vector(self, init_state, shots, tol):
state = init_state(1)
with mimic_execution_for_apply(dev):
- dev.apply([qml.QubitStateVector(state, wires=[0])])
+ dev.apply([qml.StatePrep(state, wires=[0])])
res = dev._state
expected = state
@@ -310,7 +310,7 @@ def test_single_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0]),
+ qml.StatePrep(state, wires=[0]),
qml.__getattribute__(name)(wires=[0]),
]
)
@@ -330,7 +330,7 @@ def test_single_qubit_parameters(self, init_state, shots, name, func, theta, tol
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0]),
+ qml.StatePrep(state, wires=[0]),
qml.__getattribute__(name)(theta, wires=[0]),
]
)
@@ -350,7 +350,7 @@ def test_rotation(self, init_state, shots, tol):
c = -0.654
with mimic_execution_for_apply(dev):
- dev.apply([qml.QubitStateVector(state, wires=[0]), qml.Rot(a, b, c, wires=[0])])
+ dev.apply([qml.StatePrep(state, wires=[0]), qml.Rot(a, b, c, wires=[0])])
res = dev._state
expected = rot(a, b, c) @ state
@@ -366,7 +366,7 @@ def test_two_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1]),
+ qml.StatePrep(state, wires=[0, 1]),
qml.__getattribute__(name)(wires=[0, 1]),
]
)
@@ -385,7 +385,7 @@ def test_qubit_unitary(self, init_state, shots, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=list(range(N))),
+ qml.StatePrep(state, wires=list(range(N))),
qml.QubitUnitary(mat, wires=list(range(N))),
]
)
@@ -413,7 +413,7 @@ def test_three_qubit_no_parameters(self, init_state, shots, name, mat, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1, 2]),
+ qml.StatePrep(state, wires=[0, 1, 2]),
qml.__getattribute__(name)(wires=[0, 1, 2]),
]
)
@@ -433,7 +433,7 @@ def test_two_qubits_parameters(self, init_state, shots, name, func, theta, tol):
with mimic_execution_for_apply(dev):
dev.apply(
[
- qml.QubitStateVector(state, wires=[0, 1]),
+ qml.StatePrep(state, wires=[0, 1]),
qml.__getattribute__(name)(theta, wires=[0, 1]),
]
)
diff --git a/tests/test_mixed_simulator_device.py b/tests/test_mixed_simulator_device.py
index 589f3b9..5e16f9f 100644
--- a/tests/test_mixed_simulator_device.py
+++ b/tests/test_mixed_simulator_device.py
@@ -149,16 +149,16 @@ def test_apply_operation_two_wires_no_parameters(
(qml.BasisState, [0, 0, 1, 0], [1, 0]),
(qml.BasisState, [0, 0, 1, 0], [1, 0]),
(qml.BasisState, [0, 0, 0, 1], [1, 1]),
- (qml.QubitStateVector, [0, 0, 1, 0], [0, 0, 1, 0]),
- (qml.QubitStateVector, [0, 0, 1, 0], [0, 0, 1, 0]),
- (qml.QubitStateVector, [0, 0, 0, 1], [0, 0, 0, 1]),
+ (qml.StatePrep, [0, 0, 1, 0], [0, 0, 1, 0]),
+ (qml.StatePrep, [0, 0, 1, 0], [0, 0, 1, 0]),
+ (qml.StatePrep, [0, 0, 0, 1], [0, 0, 0, 1]),
(
- qml.QubitStateVector,
+ qml.StatePrep,
[1 / math.sqrt(3), 0, 1 / math.sqrt(3), 1 / math.sqrt(3)],
[1 / math.sqrt(3), 0, 1 / math.sqrt(3), 1 / math.sqrt(3)],
),
(
- qml.QubitStateVector,
+ qml.StatePrep,
[1 / math.sqrt(3), 0, -1 / math.sqrt(3), 1 / math.sqrt(3)],
[1 / math.sqrt(3), 0, -1 / math.sqrt(3), 1 / math.sqrt(3)],
),
@@ -437,18 +437,19 @@ 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):
- """Tests that application of QubitStateVector raises an error if is not
+ @pytest.mark.parametrize("stateprep", (qml.QubitStateVector, qml.StatePrep))
+ def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire, stateprep):
+ """Tests that application of StatePrep raises an error if is not
the first operation."""
simulator_device_1_wire.reset()
with pytest.raises(
qml.DeviceError,
- match="The operation QubitStateVector is only supported at the beginning of a circuit.",
+ match=f"The operation {stateprep.__name__} is only supported at the beginning of a circuit.",
):
simulator_device_1_wire.apply(
- [qml.PauliX(0), qml.QubitStateVector(np.array([0, 1]), wires=[0])]
+ [qml.PauliX(0), stateprep(np.array([0, 1]), wires=[0])]
)
@@ -468,17 +469,18 @@ 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):
- """Tests that application of QubitStateVector raises an error if the device
+ @pytest.mark.parametrize("stateprep", (qml.QubitStateVector, qml.StatePrep))
+ def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire, stateprep):
+ """Tests that application of StatePrep raises an error if the device
is not in analytic mode."""
simulator_device_1_wire.reset()
with pytest.raises(
qml.DeviceError,
- match="The operation QubitStateVector is only supported in analytic mode.",
+ match="The operations StatePrep and QubitStateVector are only supported in analytic mode.",
):
- simulator_device_1_wire.apply([qml.QubitStateVector(np.array([0, 1]), wires=[0])])
+ simulator_device_1_wire.apply([stateprep(np.array([0, 1]), wires=[0])])
@pytest.mark.parametrize("shots", [None])
@@ -527,7 +529,7 @@ def test_expval_single_wire_no_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
+ [qml.StatePrep(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
)
res = simulator_device_1_wire.expval(op)
@@ -556,7 +558,7 @@ def test_expval_single_wire_with_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
+ [qml.StatePrep(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
)
res = simulator_device_1_wire.expval(op)
@@ -642,7 +644,7 @@ def test_expval_two_wires_with_parameters(
simulator_device_2_wires.reset()
simulator_device_2_wires.apply(
- [qml.QubitStateVector(np.array(input), wires=[0, 1])],
+ [qml.StatePrep(np.array(input), wires=[0, 1])],
rotations=op.diagonalizing_gates(),
)
@@ -726,7 +728,7 @@ def test_var_single_wire_no_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])],
+ [qml.StatePrep(np.array(input), wires=[0])],
rotations=op.diagonalizing_gates(),
)
@@ -762,7 +764,7 @@ def test_var_single_wire_with_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])],
+ [qml.StatePrep(np.array(input), wires=[0])],
rotations=op.diagonalizing_gates(),
)
@@ -817,7 +819,7 @@ def test_var_two_wires_with_parameters(
simulator_device_2_wires.reset()
simulator_device_2_wires.apply(
- [qml.QubitStateVector(np.array(input), wires=[0, 1])],
+ [qml.StatePrep(np.array(input), wires=[0, 1])],
rotations=op.diagonalizing_gates(),
)
diff --git a/tests/test_qsim_device.py b/tests/test_qsim_device.py
index 13c0b03..229d3dd 100644
--- a/tests/test_qsim_device.py
+++ b/tests/test_qsim_device.py
@@ -69,10 +69,10 @@ def circuit(x, y, z):
@pytest.mark.parametrize("shots", [8192, None])
@pytest.mark.parametrize(
- "op, params", [(qml.QubitStateVector, np.array([0, 1])), (qml.BasisState, np.array([1]))]
+ "op, params", [(qml.StatePrep, np.array([0, 1])), (qml.QubitStateVector, np.array([0, 1])), (qml.BasisState, np.array([1]))]
)
def test_decomposition(self, shots, op, params, mocker):
- """Test that QubitStateVector and BasisState are decomposed"""
+ """Test that StatePrep and BasisState are decomposed"""
dev = qml.device("cirq.qsim", wires=1, shots=shots)
@@ -101,8 +101,9 @@ def test_adjoint_ops_not_supported(self):
@pytest.mark.parametrize(
"gate",
[
- "QubitStateVector",
+ "StatePrep",
"BasisState",
+ "QubitStateVector",
"CRX",
"CRY",
"CRZ",
diff --git a/tests/test_qsimh_device.py b/tests/test_qsimh_device.py
index 9098946..c943b6e 100644
--- a/tests/test_qsimh_device.py
+++ b/tests/test_qsimh_device.py
@@ -60,10 +60,10 @@ def circuit(x, y, z):
@pytest.mark.parametrize("shots", [8192])
@pytest.mark.parametrize(
- "op, params", [(qml.QubitStateVector, np.array([0, 1])), (qml.BasisState, np.array([1]))]
+ "op, params", [(qml.StatePrep, np.array([0, 1])), (qml.QubitStateVector, np.array([0, 1])), (qml.BasisState, np.array([1]))]
)
def test_decomposition(self, shots, op, params, mocker):
- """Test that QubitStateVector and BasisState are decomposed"""
+ """Test that StatePrep and BasisState are decomposed"""
dev = qml.device("cirq.qsimh", wires=1, shots=shots, qsimh_options=qsimh_options)
@@ -92,6 +92,7 @@ def test_adjoint_ops_not_supported(self):
@pytest.mark.parametrize(
"gate",
[
+ "StatePrep",
"QubitStateVector",
"BasisState",
"CRX",
diff --git a/tests/test_simulator_device.py b/tests/test_simulator_device.py
index 5df9175..bb94794 100644
--- a/tests/test_simulator_device.py
+++ b/tests/test_simulator_device.py
@@ -193,16 +193,16 @@ def test_apply_operation_two_wires_no_parameters(
(qml.BasisState, [0, 0, 1, 0], [1, 0]),
(qml.BasisState, [0, 0, 1, 0], [1, 0]),
(qml.BasisState, [0, 0, 0, 1], [1, 1]),
- (qml.QubitStateVector, [0, 0, 1, 0], [0, 0, 1, 0]),
- (qml.QubitStateVector, [0, 0, 1, 0], [0, 0, 1, 0]),
- (qml.QubitStateVector, [0, 0, 0, 1], [0, 0, 0, 1]),
+ (qml.StatePrep, [0, 0, 1, 0], [0, 0, 1, 0]),
+ (qml.StatePrep, [0, 0, 1, 0], [0, 0, 1, 0]),
+ (qml.StatePrep, [0, 0, 0, 1], [0, 0, 0, 1]),
(
- qml.QubitStateVector,
+ qml.StatePrep,
[1 / math.sqrt(3), 0, 1 / math.sqrt(3), 1 / math.sqrt(3)],
[1 / math.sqrt(3), 0, 1 / math.sqrt(3), 1 / math.sqrt(3)],
),
(
- qml.QubitStateVector,
+ qml.StatePrep,
[1 / math.sqrt(3), 0, -1 / math.sqrt(3), 1 / math.sqrt(3)],
[1 / math.sqrt(3), 0, -1 / math.sqrt(3), 1 / math.sqrt(3)],
),
@@ -470,18 +470,19 @@ 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):
- """Tests that application of QubitStateVector raises an error if is not
+ @pytest.mark.parametrize("stateprep", (qml.StatePrep, qml.QubitStateVector))
+ def test_qubit_state_vector_not_at_beginning_error(self, simulator_device_1_wire, stateprep):
+ """Tests that application of StatePrep raises an error if is not
the first operation."""
simulator_device_1_wire.reset()
with pytest.raises(
qml.DeviceError,
- match="The operation QubitStateVector is only supported at the beginning of a circuit.",
+ match=f"The operation {stateprep.__name__} is only supported at the beginning of a circuit.",
):
simulator_device_1_wire.apply(
- [qml.PauliX(0), qml.QubitStateVector(np.array([0, 1]), wires=[0])]
+ [qml.PauliX(0), stateprep(np.array([0, 1]), wires=[0])]
)
@@ -501,17 +502,18 @@ 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):
- """Tests that application of QubitStateVector raises an error if the device
+ @pytest.mark.parametrize("stateprep", (qml.QubitStateVector, qml.StatePrep))
+ def test_qubit_state_vector_not_analytic_error(self, simulator_device_1_wire, stateprep):
+ """Tests that application of StatePrep raises an error if the device
is not in analytic mode."""
simulator_device_1_wire.reset()
with pytest.raises(
qml.DeviceError,
- match="The operation QubitStateVector is only supported in analytic mode.",
+ match="The operations StatePrep and QubitStateVector are only supported in analytic mode.",
):
- simulator_device_1_wire.apply([qml.QubitStateVector(np.array([0, 1]), wires=[0])])
+ simulator_device_1_wire.apply([stateprep(np.array([0, 1]), wires=[0])])
@pytest.mark.parametrize("shots", [None])
@@ -560,7 +562,7 @@ def test_expval_single_wire_no_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
+ [qml.StatePrep(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
)
res = simulator_device_1_wire.expval(op)
@@ -589,7 +591,7 @@ def test_expval_single_wire_with_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
+ [qml.StatePrep(np.array(input), wires=[0])], rotations=op.diagonalizing_gates()
)
res = simulator_device_1_wire.expval(op)
@@ -675,7 +677,7 @@ def test_expval_two_wires_with_parameters(
simulator_device_2_wires.reset()
simulator_device_2_wires.apply(
- [qml.QubitStateVector(np.array(input), wires=[0, 1])],
+ [qml.StatePrep(np.array(input), wires=[0, 1])],
rotations=op.diagonalizing_gates(),
)
@@ -714,7 +716,7 @@ def test_var_single_wire_no_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])],
+ [qml.StatePrep(np.array(input), wires=[0])],
rotations=op.diagonalizing_gates(),
)
@@ -750,7 +752,7 @@ def test_var_single_wire_with_parameters(
simulator_device_1_wire.reset()
simulator_device_1_wire.apply(
- [qml.QubitStateVector(np.array(input), wires=[0])],
+ [qml.StatePrep(np.array(input), wires=[0])],
rotations=op.diagonalizing_gates(),
)
@@ -801,7 +803,7 @@ def test_var_two_wires_with_parameters(
simulator_device_2_wires.reset()
simulator_device_2_wires.apply(
- [qml.QubitStateVector(np.array(input), wires=[0, 1])],
+ [qml.StatePrep(np.array(input), wires=[0, 1])],
rotations=op.diagonalizing_gates(),
)