Skip to content

Commit

Permalink
Missing unit tests for benchmarking circuits (#2366)
Browse files Browse the repository at this point in the history
* mirror circuits

* randomized benchmarking

* clifford t + ruff
  • Loading branch information
purva-thakre authored May 15, 2024
1 parent 7a7bbfd commit aefc5ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mitiq/benchmarks/tests/test_mirror_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ def test_two_qubit_gate_unsupported():
)


def test_two_qubit_gate_bad_probability():
with pytest.raises(
ValueError, match="two_qubit_gate_prob must be between 0 and 1"
):
mirror_circuits.generate_mirror_circuit(1, 2.0, nx.complete_graph(2))


def test_deterministic_correct_bitstrings():
"""For a fixed seed, correct bitstrings should be deterministic."""
expected_correct_bitstrings = (
Expand Down
8 changes: 8 additions & 0 deletions mitiq/benchmarks/tests/test_randomized_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ def test_rb_conversion(n_qubits, return_type):
)
for qc in circuits:
assert return_type in qc.__module__


def test_bad_n_qubits():
with pytest.raises(
ValueError, match="Only generates RB circuits on one or two "
):
for trials in [2, 3]:
generate_rb_circuits(n_qubits=4, num_cliffords=10, trials=trials)
18 changes: 18 additions & 0 deletions mitiq/benchmarks/tests/test_randomized_clifford_t_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ def test_conversion(return_type):
return_type=return_type,
)
assert return_type in circuit.__module__


@pytest.mark.parametrize(
"test_num_qubits, test_num_twoq_cliffords, error_msg",
[
(0, 2, "Cannot prepare a circuit with"),
(1, 2, "Need more than 2 qubits for two-qubit Clifford gates."),
],
)
def test_invalid_input(test_num_qubits, test_num_twoq_cliffords, error_msg):
"""Ensures error raised as expected."""
with pytest.raises(ValueError, match=error_msg):
generate_random_clifford_t_circuit(
num_qubits=test_num_qubits,
num_oneq_cliffords=2,
num_twoq_cliffords=test_num_twoq_cliffords,
num_t_gates=2,
)

0 comments on commit aefc5ce

Please sign in to comment.