Skip to content

Commit

Permalink
solve pylint and apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisAlfredoNu committed Sep 27, 2024
1 parent e9c4efa commit 84d1b8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 14 additions & 3 deletions mpitests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def circuit():
qml.RX(0.4, wires=[0])
return qml.expval(qml.PauliZ(0))

qnode = QNode(circuit, dev, diff_method="adjoint")
result = QNode(circuit, dev, diff_method="adjoint")

jac = qml.grad(qnode)()
jac = qml.grad(result)()

assert len(jac) == 0

Expand Down Expand Up @@ -222,7 +222,18 @@ def test_Rot_gradient(self, stateprep, theta, batch_obs, dev):
@pytest.mark.parametrize("param", [1, -2, 1.623, -0.051, 0]) # integers, floats, zero
@pytest.mark.parametrize(
"rotation,obs,expected_func",
[(qml.RY, qml.PauliX, lambda x: np.cos(x)), (qml.RX, qml.PauliZ, lambda x: -np.sin(x))],
[
(
qml.RY,

Check notice on line 227 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L227

Trailing whitespace (trailing-whitespace)
qml.PauliX,

Check notice on line 228 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L228

Trailing whitespace (trailing-whitespace)
lambda x: np.cos(x)

Check notice on line 229 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L229

Lambda may not be necessary (unnecessary-lambda)
),

Check notice on line 230 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L230

Trailing whitespace (trailing-whitespace)
(
qml.RX,

Check notice on line 232 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L232

Trailing whitespace (trailing-whitespace)
qml.PauliZ,

Check notice on line 233 in mpitests/test_adjoint_jacobian.py

View check run for this annotation

codefactor.io / CodeFactor

mpitests/test_adjoint_jacobian.py#L233

Trailing whitespace (trailing-whitespace)
lambda x: -np.sin(x)
),
],
)
@pytest.mark.parametrize("batch_obs", [True, False])
def test_r_gradient(
Expand Down
5 changes: 2 additions & 3 deletions mpitests/test_expval.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ def test_expval_single_wire_no_parameters(self, tol, operation, wires, C_DTYPE,
"""Tests that expectation values are properly calculated for single-wire observables without parameters."""
num_wires = numQubits
comm = MPI.COMM_WORLD
commSize = comm.Get_size()
num_global_wires = commSize.bit_length() - 1
num_local_wires = num_wires - num_global_wires

dev_mpi = qml.device(
"lightning.gpu", wires=numQubits, mpi=True, c_dtype=C_DTYPE, batch_obs=batch_obs
Expand Down Expand Up @@ -436,5 +433,7 @@ def circuit():
expected_val = -(
np.cos(varphi) * np.sin(phi) + np.sin(varphi) * np.cos(theta)
) / np.sqrt(2)
else:
expected_val = 0

assert np.allclose(res, expected_val, atol=tol)

0 comments on commit 84d1b8c

Please sign in to comment.