Update variable naming
This commit is contained in:
@@ -69,13 +69,13 @@ def test_eval(nqubits: int, dtype="complex128"):
|
|||||||
), "Resulting dense vectors do not match"
|
), "Resulting dense vectors do not match"
|
||||||
|
|
||||||
# Test with explicit settings specified.
|
# Test with explicit settings specified.
|
||||||
computation_settings = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": False,
|
"expectation_enabled": False,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
print(
|
print(
|
||||||
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
||||||
@@ -104,13 +104,13 @@ def test_mps(nqubits: int, dtype="complex128"):
|
|||||||
# Test cutensornet
|
# Test cutensornet
|
||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
# Test with simple MPS settings specified using bool. Uses the default MPS parameters.
|
# Test with simple MPS settings specified using bool. Uses the default MPS parameters.
|
||||||
computation_settings_1 = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": True,
|
"MPS_enabled": True,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": False,
|
"expectation_enabled": False,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_1)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
print(
|
print(
|
||||||
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
||||||
@@ -120,7 +120,7 @@ def test_mps(nqubits: int, dtype="complex128"):
|
|||||||
), "Resulting dense vectors do not match"
|
), "Resulting dense vectors do not match"
|
||||||
|
|
||||||
# Test with explicit MPS computation settings specified using Dict. Users able to specify parameters like qr_method etc.
|
# Test with explicit MPS computation settings specified using Dict. Users able to specify parameters like qr_method etc.
|
||||||
computation_settings_2 = {
|
comp_set_w_MPS_config_para = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": {
|
"MPS_enabled": {
|
||||||
"qr_method": False,
|
"qr_method": False,
|
||||||
@@ -132,7 +132,7 @@ def test_mps(nqubits: int, dtype="complex128"):
|
|||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": False,
|
"expectation_enabled": False,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_2)
|
backend.configure_tn_simulation(comp_set_w_MPS_config_para)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
print(
|
print(
|
||||||
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
f"State vector difference: {abs(result_tn.statevector.flatten() - result_sv_cp).max():0.3e}"
|
||||||
@@ -159,26 +159,26 @@ def test_expectation(nqubits: int, dtype="complex128"):
|
|||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
|
|
||||||
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
||||||
computation_settings_1 = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": True,
|
"expectation_enabled": True,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_1)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
assert math.isclose(
|
assert math.isclose(
|
||||||
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
||||||
computation_settings_2 = {
|
comp_set_w_hamiltonian_obj = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": ham,
|
"expectation_enabled": ham,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_2)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_obj)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
assert math.isclose(
|
assert math.isclose(
|
||||||
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
||||||
@@ -186,13 +186,13 @@ def test_expectation(nqubits: int, dtype="complex128"):
|
|||||||
|
|
||||||
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
||||||
ham_dict = build_observable_dict(nqubits)
|
ham_dict = build_observable_dict(nqubits)
|
||||||
computation_settings_3 = {
|
comp_set_w_hamiltonian_dict = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": ham_dict,
|
"expectation_enabled": ham_dict,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_3)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_dict)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
assert math.isclose(
|
assert math.isclose(
|
||||||
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
exact_expval.item(), result_tn.real.get().item(), abs_tol=ABS_TOL
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ def test_eval_mpi(nqubits: int, dtype="complex128"):
|
|||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
|
|
||||||
# Test with explicit settings specified.
|
# Test with explicit settings specified.
|
||||||
computation_settings = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": True,
|
"MPI_enabled": True,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": False,
|
"expectation_enabled": False,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
result_tn_cp = cp.asarray(result_tn.statevector.flatten())
|
result_tn_cp = cp.asarray(result_tn.statevector.flatten())
|
||||||
|
|
||||||
@@ -109,13 +109,13 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
|||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
|
|
||||||
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
||||||
computation_settings_1 = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": True,
|
"MPI_enabled": True,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": True,
|
"expectation_enabled": True,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_1)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
@@ -133,13 +133,13 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
|||||||
), f"Rank {backend.rank}: expected int array [0], got {result_tn}"
|
), f"Rank {backend.rank}: expected int array [0], got {result_tn}"
|
||||||
|
|
||||||
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
||||||
computation_settings_2 = {
|
comp_set_w_hamiltonian_obj = {
|
||||||
"MPI_enabled": True,
|
"MPI_enabled": True,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": ham,
|
"expectation_enabled": ham,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_2)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_obj)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
@@ -158,13 +158,13 @@ def test_expectation_mpi(nqubits: int, dtype="complex128"):
|
|||||||
|
|
||||||
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
||||||
ham_dict = build_observable_dict(nqubits)
|
ham_dict = build_observable_dict(nqubits)
|
||||||
computation_settings_3 = {
|
comp_set_w_hamiltonian_dict = {
|
||||||
"MPI_enabled": True,
|
"MPI_enabled": True,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": False,
|
"NCCL_enabled": False,
|
||||||
"expectation_enabled": ham_dict,
|
"expectation_enabled": ham_dict,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_3)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_dict)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
@@ -201,13 +201,13 @@ def test_eval_nccl(nqubits: int, dtype="complex128"):
|
|||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
|
|
||||||
# Test with explicit settings specified.
|
# Test with explicit settings specified.
|
||||||
computation_settings = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": True,
|
"NCCL_enabled": True,
|
||||||
"expectation_enabled": False,
|
"expectation_enabled": False,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
result_tn_cp = cp.asarray(result_tn.statevector.flatten())
|
result_tn_cp = cp.asarray(result_tn.statevector.flatten())
|
||||||
|
|
||||||
@@ -242,13 +242,13 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
|||||||
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
backend = construct_backend(backend="qibotn", platform="cutensornet")
|
||||||
|
|
||||||
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
# Test with simple settings using bool. Uses default Hamilitonian for expectation calculation.
|
||||||
computation_settings_1 = {
|
comp_set_w_bool = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": True,
|
"NCCL_enabled": True,
|
||||||
"expectation_enabled": True,
|
"expectation_enabled": True,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_1)
|
backend.configure_tn_simulation(comp_set_w_bool)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
@@ -266,13 +266,13 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
|||||||
), f"Rank {backend.rank}: expected int array [0], got {result_tn}"
|
), f"Rank {backend.rank}: expected int array [0], got {result_tn}"
|
||||||
|
|
||||||
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
# Test with user defined hamiltonian using "hamiltonians.SymbolicHamiltonian" object.
|
||||||
computation_settings_2 = {
|
comp_set_w_hamiltonian_obj = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": True,
|
"NCCL_enabled": True,
|
||||||
"expectation_enabled": ham,
|
"expectation_enabled": ham,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_2)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_obj)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
@@ -291,13 +291,13 @@ def test_expectation_NCCL(nqubits: int, dtype="complex128"):
|
|||||||
|
|
||||||
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
# Test with user defined hamiltonian using Dictionary object form of hamiltonian.
|
||||||
ham_dict = build_observable_dict(nqubits)
|
ham_dict = build_observable_dict(nqubits)
|
||||||
computation_settings_3 = {
|
comp_set_w_hamiltonian_dict = {
|
||||||
"MPI_enabled": False,
|
"MPI_enabled": False,
|
||||||
"MPS_enabled": False,
|
"MPS_enabled": False,
|
||||||
"NCCL_enabled": True,
|
"NCCL_enabled": True,
|
||||||
"expectation_enabled": ham_dict,
|
"expectation_enabled": ham_dict,
|
||||||
}
|
}
|
||||||
backend.configure_tn_simulation(computation_settings_3)
|
backend.configure_tn_simulation(comp_set_w_hamiltonian_dict)
|
||||||
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
result_tn = backend.execute_circuit(circuit=qibo_circ)
|
||||||
if backend.rank == 0:
|
if backend.rank == 0:
|
||||||
# Compare numerical values
|
# Compare numerical values
|
||||||
|
|||||||
Reference in New Issue
Block a user