Skip to content

Commit aae6632

Browse files
authored
Improve test coverage for qiskit_backend.py to 99% (#1112)
* test: add fallback test for qiskit custom simulator * test: add coverage for draw_circuit method across all backends * test: add coverage for apply_swap_gate function across all backends
1 parent 52bc028 commit aae6632

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

testing/qumat/test_create_circuit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,33 @@ def test_missing_backend_options_raises_keyerror(self):
194194

195195
with pytest.raises(KeyError, match="missing required key.*backend_options"):
196196
QuMat(config)
197+
198+
def test_qiskit_custom_simulator_fallback(self):
199+
"""Test that Qiskit backend accepts simulator types outside the legacy map."""
200+
config = {
201+
"backend_name": "qiskit",
202+
"backend_options": {"simulator_type": "matrix_product_state"},
203+
}
204+
205+
qumat = QuMat(config)
206+
207+
assert qumat.backend is not None
208+
assert qumat.backend.options.method == "matrix_product_state"
209+
210+
211+
@pytest.mark.parametrize("backend_name", TESTING_BACKENDS)
212+
class TestCircuitDrawing:
213+
"""Test class for circuit drawing functionality."""
214+
215+
def test_draw_circuit_returns_output(self, backend_name):
216+
"""Test that draw_circuit runs successfully and returns an output."""
217+
backend_config = get_backend_config(backend_name)
218+
qumat = QuMat(backend_config)
219+
220+
qumat.create_empty_circuit(num_qubits=2)
221+
qumat.apply_hadamard_gate(0)
222+
qumat.apply_cnot_gate(0, 1)
223+
224+
drawing = qumat.draw_circuit()
225+
226+
assert drawing is not None

testing/qumat/test_multi_qubit_gates.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,19 @@ def test_cnot_cross_backend_consistency(self, backend_name):
490490
assert abs(probabilities[i] - probabilities[j]) < 0.05, (
491491
f"Backends have inconsistent CNOT results: {results_dict}"
492492
)
493+
494+
495+
@pytest.mark.parametrize("backend_name", TESTING_BACKENDS)
496+
def test_apply_swap_gate(backend_name):
497+
"""Test that the SWAP gate applies correctly across backends."""
498+
backend_config = get_backend_config(backend_name)
499+
qumat = QuMat(backend_config)
500+
501+
qumat.create_empty_circuit(num_qubits=2)
502+
503+
qumat.apply_pauli_x_gate(0)
504+
505+
qumat.apply_swap_gate(0, 1)
506+
507+
results = qumat.execute_circuit()
508+
assert results is not None

0 commit comments

Comments
 (0)