Skip to content

Commit 2e8fcf3

Browse files
committed
🧪 [testing improvement] Add error path test for invalid number of target qubits in add_op_to_circuit
Addresses a testing gap in `qsimcirq/qsim_circuit.py` where the `NotImplementedError` for controlled gates with more than 4 target qubits was not explicitly tested. 🎯 **What:** The testing gap addressed - Added `test_add_op_to_circuit_too_many_targets` to `qsimcirq_tests/qsimcirq_test.py`. 📊 **Coverage:** What scenarios are now tested - Controlled gates with more than 4 target qubits (specifically 5 targets) are now verified to raise `NotImplementedError` with the correct error message. ✨ **Result:** The improvement in test coverage - Increased reliability of the `add_op_to_circuit` function by covering a previously untested error path.
1 parent a78d121 commit 2e8fcf3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎qsimcirq_tests/qsimcirq_test.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,23 @@ def test_control_limits():
879879
_ = qsimSim.simulate(cirq.Circuit(CHHHHH), qubit_order=qubits)
880880

881881

882+
def test_add_op_to_circuit_too_many_targets():
883+
# qsim supports up to 4 target qubits for controlled gates.
884+
qubits = cirq.LineQubit.range(6)
885+
# A gate with 5 targets and 1 control.
886+
big_gate = (
887+
cirq.MatrixGate(np.eye(32)).on(*qubits[1:]).controlled_by(qubits[0])
888+
)
889+
890+
qsim_circuit = qsimcirq.qsim.Circuit()
891+
qubit_to_index = {q: i for i, q in enumerate(qubits)}
892+
893+
with pytest.raises(
894+
NotImplementedError, match="Received control gate on 5 target qubits"
895+
):
896+
qsimcirq.add_op_to_circuit(big_gate, 0, qubit_to_index, qsim_circuit)
897+
898+
882899
def test_decomposable_gate():
883900
qubits = cirq.LineQubit.range(4)
884901

0 commit comments

Comments
 (0)