Skip to content

Commit

Permalink
solved errors on gates
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone-Bordoni committed Feb 26, 2024
1 parent 5c504be commit 8fe4bf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/qibo/backends/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ def cast(
"""
if dtype is None:
dtype = self.dtype
elif isinstance(dtype, self.np.dtype):
dtype = dtype
elif isinstance(dtype, type):
dtype = torch_dtype_dict[dtype.__name__]
else:
elif not isinstance(dtype, torch.dtype):
dtype = torch_dtype_dict[str(dtype)]

if isinstance(x, self.np.Tensor):
Expand Down
13 changes: 9 additions & 4 deletions tests/test_gates_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ def test_u3(backend, seed_state, seed_observable):
backend.cast(np.transpose(np.conj(final_state_decompose)))
@ observable
@ final_state_decompose,
backend.cast(np.transpose(np.conj(target_state))) @ observable @ target_state,
backend.cast(np.transpose(np.conj(target_state)))
@ observable
@ backend.cast(target_state),
)

assert gates.U3(0, theta, phi, lam).qasm_label == "u3"
assert not gates.U3(0, theta, phi, lam).clifford
assert gates.U3(0, theta, phi, lam).unitary
Expand Down Expand Up @@ -527,7 +528,9 @@ def test_cy(backend, controlled_by, seed_state, seed_observable):
backend.cast(np.transpose(np.conj(final_state_decompose)))
@ observable
@ final_state_decompose,
backend.cast(np.transpose(np.conj(target_state))) @ observable @ target_state,
backend.cast(np.transpose(np.conj(target_state)))
@ observable
@ backend.cast(target_state),
)

assert gates.CY(0, 1).qasm_label == "cy"
Expand Down Expand Up @@ -571,7 +574,9 @@ def test_cz(backend, controlled_by, seed_state, seed_observable):
backend.cast(np.transpose(np.conj(final_state_decompose)))
@ observable
@ final_state_decompose,
backend.cast(np.transpose(np.conj(target_state))) @ observable @ target_state,
backend.cast(np.transpose(np.conj(target_state)))
@ observable
@ backend.cast(target_state),
)

assert gates.CZ(0, 1).qasm_label == "cz"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ def test_measurement_gate(backend, n, nshots):
def test_multiple_qubit_measurement_gate(backend):
c = models.Circuit(2)
c.add(gates.X(0))
c.add(gates.M(0, 1))
measure = c.add(gates.M(0, 1))
result = backend.execute_circuit(c, nshots=100)
print(result.frequencies())
print(result.probabilities())
# print(measure.samples())
target_binary_samples = np.zeros((100, 2))
target_binary_samples[:, 0] = 1
assert_result(
Expand Down

0 comments on commit 8fe4bf2

Please sign in to comment.