Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for cupy and cuquantum backends #1238

Merged
merged 24 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
94c3f64
fix clifford
renatomello Feb 29, 2024
7ac7321
fix encodings
renatomello Feb 29, 2024
234ab65
rename file
renatomello Mar 1, 2024
2a79796
remove comment
renatomello Mar 1, 2024
002e603
Merge branch 'master' into cuquantum_tests
renatomello Mar 6, 2024
973b0f2
Merge branch 'master' into cuquantum_tests
renatomello Mar 6, 2024
7f331ad
Merge branch 'master' into cuquantum_tests
renatomello Mar 9, 2024
d1e22df
Merge branch 'master' into cuquantum_tests
renatomello Mar 14, 2024
73b677e
Merge branch 'master' into cuquantum_tests
renatomello Mar 14, 2024
42a0e74
Merge branch 'master' into cuquantum_tests
renatomello Mar 14, 2024
46b7b89
fix more tests
renatomello Mar 14, 2024
b70dcdb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 14, 2024
18d59d7
move function from `quantum_info.random_ensembles` to `backends.__ini…
renatomello Mar 15, 2024
b4e8384
introduce `seed` to `models.error_mitigation` and fix GPU tests
renatomello Mar 15, 2024
1a577e1
remove function
renatomello Mar 15, 2024
4632a6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2024
033e968
fix more tests
renatomello Mar 16, 2024
fbc06c8
fix transpiler tests
renatomello Mar 16, 2024
9a744a7
update lock
renatomello Mar 16, 2024
7d85dd0
Merge branch 'master' into cuquantum_tests
renatomello Mar 18, 2024
56e506a
Merge branch 'master' into cuquantum_tests
renatomello Mar 20, 2024
d58825d
Merge branch 'master' into cuquantum_tests
renatomello Mar 23, 2024
8be0a0b
Merge branch 'master' into cuquantum_tests
renatomello Apr 27, 2024
7e04b68
Merge branch 'master' into cuquantum_tests
MatteoRobbiati May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
13 changes: 9 additions & 4 deletions tests/test_models_encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,22 @@ def test_unary_encoder(backend, nqubits, architecture, kind):
# sampling random data in interval [-1, 1]
sampler = np.random.default_rng(1)
data = 2 * sampler.random(nqubits) - 1
data = backend.cast(data, dtype=data.dtype)
data = data.tolist() if kind is not None else backend.cast(data, dtype=data.dtype)

if kind is not None:
data = kind(data)
print(type(data), type(data[0]))

# if kind is not None:
# data = kind(data)

circuit = unary_encoder(data, architecture=architecture)
state = backend.execute_circuit(circuit).state()
indexes = np.flatnonzero(state)
state = np.real(state[indexes])

backend.assert_allclose(state, data / backend.calculate_norm(data, order=2))
backend.assert_allclose(
state,
backend.cast(data, dtype=backend.dtype) / backend.calculate_norm(data, order=2),
)


@pytest.mark.parametrize("seed", [None, 10, np.random.default_rng(10)])
Expand Down
31 changes: 14 additions & 17 deletions tests/test_quantum_info_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@


def construct_clifford_backend(backend):
if isinstance(backend, TensorflowBackend):
if backend.__class__.__name__ in ["TensorflowBackend", "CuQuantumBackend"]:
with pytest.raises(NotImplementedError):
clifford_backend = CliffordBackend(backend.name)
else:
return CliffordBackend(_get_engine_name(backend))
pytest.skip("Clifford backend not defined for the this engine.")

return CliffordBackend(_get_engine_name(backend))


@pytest.mark.parametrize("nqubits", [2, 10, 50, 100])
Expand Down Expand Up @@ -62,8 +63,7 @@ def test_clifford_from_circuit(backend, measurement):
@pytest.mark.parametrize("algorithm", ["AG04", "BM20"])
@pytest.mark.parametrize("nqubits", [1, 2, 3, 10, 50])
def test_clifford_to_circuit(backend, nqubits, algorithm, seed):
if backend.__class__.__name__ == "TensorflowBackend":
pytest.skip("CliffordBackend not defined for Tensorflow engine.")
clifford_backend = construct_clifford_backend(backend)

clifford = random_clifford(nqubits, seed=seed, backend=backend)

Expand Down Expand Up @@ -310,22 +310,19 @@ def test_clifford_samples_frequencies(backend, binary):


def test_clifford_samples_error(backend):
clifford_backend = construct_clifford_backend(backend)

c = random_clifford(1, backend=backend)
if isinstance(backend, TensorflowBackend):
with pytest.raises(NotImplementedError):
clifford_backend = CliffordBackend(backend)
else:
obj = Clifford.from_circuit(c, engine=_get_engine_name(backend))
with pytest.raises(RuntimeError) as excinfo:
obj.samples()
assert str(excinfo.value) == "No measurement provided."
obj = Clifford.from_circuit(c, engine=_get_engine_name(backend))
with pytest.raises(RuntimeError) as excinfo:
obj.samples()
assert str(excinfo.value) == "No measurement provided."


@pytest.mark.parametrize("deep", [False, True])
@pytest.mark.parametrize("nqubits", [1, 10, 100])
def test_clifford_copy(backend, nqubits, deep):
if backend.__class__.__name__ == "TensorflowBackend":
pytest.skip("CliffordBackend not defined for Tensorflow engine.")
clifford_backend = construct_clifford_backend(backend)

circuit = random_clifford(nqubits, backend=backend)
clifford = Clifford.from_circuit(circuit, engine=_get_engine_name(backend))
Expand All @@ -344,7 +341,7 @@ def test_clifford_copy(backend, nqubits, deep):

@pytest.mark.parametrize("pauli_2", ["Z", "Y", "Y"])
@pytest.mark.parametrize("pauli_1", ["X", "Y", "Z"])
def test_one_qubit_paulis_string_product(backend, pauli_1, pauli_2):
def test_one_qubit_paulis_string_product(pauli_1, pauli_2):
products = {
"XY": "iZ",
"YZ": "iX",
Expand Down Expand Up @@ -379,7 +376,7 @@ def test_one_qubit_paulis_string_product(backend, pauli_1, pauli_2):
[["iY", "iX"], "iZ"],
],
)
def test_string_product(backend, operators, target):
def test_string_product(operators, target):
product = _string_product(operators)
assert product == target

Expand Down
Loading