Make tolerance a variable
This commit is contained in:
@@ -7,6 +7,7 @@ from qibo import construct_backend, hamiltonians
|
||||
from qibo.models import QFT
|
||||
from qibo.symbols import X, Z
|
||||
|
||||
ABS_TOL = 1e-7
|
||||
|
||||
def qibo_qft(nqubits, swaps):
|
||||
circ_qibo = QFT(nqubits, swaps)
|
||||
@@ -165,7 +166,7 @@ def test_expectation(nqubits: int, dtype="complex128"):
|
||||
}
|
||||
backend.configure_tn_simulation(computation_settings_1)
|
||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=1e-7)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL)
|
||||
|
||||
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
||||
computation_settings_2 = {
|
||||
@@ -176,7 +177,7 @@ def test_expectation(nqubits: int, dtype="complex128"):
|
||||
}
|
||||
backend.configure_tn_simulation(computation_settings_2)
|
||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=1e-7)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL)
|
||||
|
||||
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
||||
ham_dict = build_observable_dict(nqubits)
|
||||
@@ -188,4 +189,4 @@ def test_expectation(nqubits: int, dtype="complex128"):
|
||||
}
|
||||
backend.configure_tn_simulation(computation_settings_3)
|
||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=1e-7)
|
||||
assert math.isclose(exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL)
|
||||
|
||||
@@ -10,6 +10,7 @@ from qibo import construct_backend, hamiltonians
|
||||
from qibo.models import QFT
|
||||
from qibo.symbols import X, Z
|
||||
|
||||
ABS_TOL = 1e-7
|
||||
|
||||
def qibo_qft(nqubits, swaps):
|
||||
circ_qibo = QFT(nqubits, swaps)
|
||||
@@ -118,7 +119,7 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
@@ -142,7 +143,7 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
@@ -167,7 +168,7 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
@@ -251,7 +252,7 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
@@ -275,7 +276,7 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
@@ -300,7 +301,7 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
||||
if backend.rank == 0:
|
||||
# Compare numerical values
|
||||
assert math.isclose(
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=1e-7
|
||||
exact_expval.item(), float(result_tn[0]), abs_tol=ABS_TOL
|
||||
), f"Rank {backend.rank}: mismatch, expected {exact_expval}, got {result_tn}"
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user