From 11d72a108ed6baed9283c57440069f29c52ce6e0 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:35:11 -0400 Subject: [PATCH] Update format --- mpitests/test_adjoint_jacobian.py | 8 ++++++-- pennylane_lightning/core/_serialize.py | 4 +++- pennylane_lightning/core/_state_vector_base.py | 1 - pennylane_lightning/lightning_kokkos/_measurements.py | 1 - pennylane_lightning/lightning_kokkos/_state_vector.py | 2 -- pennylane_lightning/lightning_qubit/_measurements.py | 1 - pennylane_lightning/lightning_qubit/_state_vector.py | 1 - tests/lightning_qubit/test_jacobian_method.py | 1 - tests/test_adjoint_jacobian.py | 8 ++++++-- tests/test_native_mcm.py | 1 - 10 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mpitests/test_adjoint_jacobian.py b/mpitests/test_adjoint_jacobian.py index 6f3b5c7f5b..dc96acab5c 100644 --- a/mpitests/test_adjoint_jacobian.py +++ b/mpitests/test_adjoint_jacobian.py @@ -1384,7 +1384,9 @@ def test_qubit_unitary(dev, n_targets): np.random.seed(1337) par = 2 * np.pi * np.random.rand(n_wires) - U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets) + U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand( + 2**n_targets, 2**n_targets + ) U, _ = np.linalg.qr(U) init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires) init_state /= np.sqrt(np.dot(np.conj(init_state), init_state)) @@ -1432,7 +1434,9 @@ def test_diff_qubit_unitary(dev, n_targets): np.random.seed(1337) par = 2 * np.pi * np.random.rand(n_wires) - U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets) + U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand( + 2**n_targets, 2**n_targets + ) U, _ = np.linalg.qr(U) init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires) init_state /= np.sqrt(np.dot(np.conj(init_state), init_state)) diff --git a/pennylane_lightning/core/_serialize.py b/pennylane_lightning/core/_serialize.py index 9cd80c9550..1eedbbda69 100644 --- a/pennylane_lightning/core/_serialize.py +++ b/pennylane_lightning/core/_serialize.py @@ -367,7 +367,9 @@ def serialize_observables(self, tape: QuantumTape, wires_map: dict = None) -> Li obs_indices.append(i) return serialized_obs, obs_indices - def serialize_ops(self, tape: QuantumTape, wires_map: dict = None) -> Tuple[ + def serialize_ops( + self, tape: QuantumTape, wires_map: dict = None + ) -> Tuple[ List[List[str]], List[np.ndarray], List[List[int]], diff --git a/pennylane_lightning/core/_state_vector_base.py b/pennylane_lightning/core/_state_vector_base.py index b2ba3a0669..3e08a5ab40 100644 --- a/pennylane_lightning/core/_state_vector_base.py +++ b/pennylane_lightning/core/_state_vector_base.py @@ -38,7 +38,6 @@ class LightningBaseStateVector(ABC): """ def __init__(self, num_wires: int, dtype: Union[np.complex128, np.complex64]): - if dtype not in [np.complex64, np.complex128]: raise TypeError(f"Unsupported complex type: {dtype}") diff --git a/pennylane_lightning/lightning_kokkos/_measurements.py b/pennylane_lightning/lightning_kokkos/_measurements.py index 6e706614ba..b438af350c 100644 --- a/pennylane_lightning/lightning_kokkos/_measurements.py +++ b/pennylane_lightning/lightning_kokkos/_measurements.py @@ -46,7 +46,6 @@ def __init__( self, kokkos_state, ) -> None: - super().__init__(kokkos_state) self._measurement_lightning = self._measurement_dtype()(kokkos_state.state_vector) diff --git a/pennylane_lightning/lightning_kokkos/_state_vector.py b/pennylane_lightning/lightning_kokkos/_state_vector.py index 5e76249de0..dda40ffadb 100644 --- a/pennylane_lightning/lightning_kokkos/_state_vector.py +++ b/pennylane_lightning/lightning_kokkos/_state_vector.py @@ -64,7 +64,6 @@ def __init__( kokkos_args=None, sync=True, ): # pylint: disable=too-many-arguments - super().__init__(num_wires, dtype) self._device_name = "lightning.kokkos" @@ -280,7 +279,6 @@ def _apply_lightning( elif isinstance(operation, qml.ops.Controlled) and isinstance( operation.base, qml.GlobalPhase ): # apply n-controlled gate - # Kokkos do not support the controlled gates except for GlobalPhase self._apply_lightning_controlled(operation) else: # apply gate as a matrix diff --git a/pennylane_lightning/lightning_qubit/_measurements.py b/pennylane_lightning/lightning_qubit/_measurements.py index f762fcb7e6..c1b97a1184 100644 --- a/pennylane_lightning/lightning_qubit/_measurements.py +++ b/pennylane_lightning/lightning_qubit/_measurements.py @@ -58,7 +58,6 @@ def __init__( kernel_name: str = None, num_burnin: int = None, ) -> None: - super().__init__(qubit_state) self._mcmc = mcmc diff --git a/pennylane_lightning/lightning_qubit/_state_vector.py b/pennylane_lightning/lightning_qubit/_state_vector.py index 0a8b0b7d6d..b4b6ef5ff1 100644 --- a/pennylane_lightning/lightning_qubit/_state_vector.py +++ b/pennylane_lightning/lightning_qubit/_state_vector.py @@ -51,7 +51,6 @@ class LightningStateVector(LightningBaseStateVector): # pylint: disable=too-few """ def __init__(self, num_wires, dtype=np.complex128): - super().__init__(num_wires, dtype) self._device_name = "lightning.qubit" diff --git a/tests/lightning_qubit/test_jacobian_method.py b/tests/lightning_qubit/test_jacobian_method.py index 745feee502..c636cbc77f 100644 --- a/tests/lightning_qubit/test_jacobian_method.py +++ b/tests/lightning_qubit/test_jacobian_method.py @@ -51,7 +51,6 @@ def calculate_reference(tape, execute_and_derivatives=False): @staticmethod def process_and_execute(statevector, tape, execute_and_derivatives=False): - wires = statevector.num_wires device = LightningDevice(wires) if execute_and_derivatives: diff --git a/tests/test_adjoint_jacobian.py b/tests/test_adjoint_jacobian.py index 83713b1c69..1eb06a0d91 100644 --- a/tests/test_adjoint_jacobian.py +++ b/tests/test_adjoint_jacobian.py @@ -1550,7 +1550,9 @@ def test_qubit_unitary(n_targets): init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires) init_state /= np.linalg.norm(init_state) init_state = np.array(init_state, requires_grad=False) - U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets) + U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand( + 2**n_targets, 2**n_targets + ) U, _ = np.linalg.qr(U) U = np.array(U, requires_grad=False) @@ -1592,7 +1594,9 @@ def test_diff_qubit_unitary(n_targets): init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires) init_state /= np.linalg.norm(init_state) init_state = np.array(init_state, requires_grad=False) - U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets) + U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand( + 2**n_targets, 2**n_targets + ) U, _ = np.linalg.qr(U) U = np.array(U, requires_grad=False) diff --git a/tests/test_native_mcm.py b/tests/test_native_mcm.py index df5ba6cb43..07281fb48a 100644 --- a/tests/test_native_mcm.py +++ b/tests/test_native_mcm.py @@ -90,7 +90,6 @@ def func(x, y): ): func(*params) if device_name == "lightning.kokkos": - with pytest.raises( qml.DeviceError, match=r"Measurement shadow\(wires=\[0\]\) not accepted with finite shots on "