Skip to content

Commit

Permalink
pass linting
Browse files Browse the repository at this point in the history
  • Loading branch information
splch committed Apr 30, 2024
1 parent 3849f11 commit c224511
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
16 changes: 10 additions & 6 deletions pennylane_ionq/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ def compute_matrix(phi0, phi1, theta): # pylint: disable=arguments-differ
pi = np.pi
i = 1j
return (
1 / np.sqrt(2) * np.array([
[cos, 0, 0, -i * exp(-2 * pi * i * (phi0 + phi1))],
[0, cos, -i * exp(-2 * pi * i * (phi0 - phi1)), 0],
[0, -i * exp(2 * pi * i * (phi0 - phi1)), cos, 0],
[-i * exp(2 * pi * i * (phi0 + phi1)), 0, 0, cos],
])
1
/ np.sqrt(2)
* np.array(
[
[cos, 0, 0, -i * exp(-2 * pi * i * (phi0 + phi1))],
[0, cos, -i * exp(-2 * pi * i * (phi0 - phi1)), 0],
[0, -i * exp(2 * pi * i * (phi0 - phi1)), cos, 0],
[-i * exp(2 * pi * i * (phi0 + phi1)), 0, 0, cos],
]
)
)


Expand Down
24 changes: 16 additions & 8 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ def mock_submit_job(*args):
"phi0, phi1, theta",
[
(0.1, 0.2, 0.25), # Default fully entangling case
(0, 0.3, 0.1), # Partially entangling case
(1.5, 2.7, 0), # No entanglement case
(0, 0.3, 0.1), # Partially entangling case
(1.5, 2.7, 0), # No entanglement case
],
)
def test_ms_gate_theta_variation(self, phi0, phi1, theta, tol=1e-6):
Expand All @@ -374,13 +374,21 @@ def test_ms_gate_theta_variation(self, phi0, phi1, theta, tol=1e-6):
computed_matrix = ms_gate.compute_matrix(*ms_gate.data)

# Expected matrix
cos = np.cos(theta / 2)
exp = np.exp
pi = np.pi
i = 1j
expected_matrix = (
1 / np.sqrt(2) * np.array([
[np.cos(theta / 2), 0, 0, -1j * np.exp(-2 * np.pi * 1j * (phi0 + phi1))],
[0, np.cos(theta / 2), -1j * np.exp(-2 * np.pi * 1j * (phi0 - phi1)), 0],
[0, -1j * np.exp(2 * np.pi * 1j * (phi0 - phi1)), np.cos(theta / 2), 0],
[-1j * np.exp(2 * np.pi * 1j * (phi0 + phi1)), 0, 0, np.cos(theta / 2)],
])
1
/ np.sqrt(2)
* np.array(
[
[cos, 0, 0, -i * exp(-2 * pi * i * (phi0 + phi1))],
[0, cos, -i * exp(-2 * pi * i * (phi0 - phi1)), 0],
[0, -i * exp(2 * pi * i * (phi0 - phi1)), cos, 0],
[-i * exp(2 * pi * i * (phi0 + phi1)), 0, 0, cos],
]
)
)

assert ms_gate.data == (phi0, phi1, theta)
Expand Down

0 comments on commit c224511

Please sign in to comment.