Qiskit-Extensions / circuit-knitting-toolbox

Tools for knitting quantum circuits with Qiskit
https://qiskit-extensions.github.io/circuit-knitting-toolbox/
Apache License 2.0
69 stars 23 forks source link

Need a test that ensures barriers are re-combined correctly in `transforms.py` #626

Open garrison opened 3 weeks ago

garrison commented 3 weeks ago

See https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/pull/625#issuecomment-2168475767. Such a test is currently lacking, and having 100% test coverage is giving us a false sense of security here.

lodenrogue commented 3 weeks ago

Any more details you can provide here? An example of what is meant by a barrier or re-combined for those of us new to this repo?

garrison commented 3 weeks ago

If you take the first tutorial notebook and place a barrier across all qubits at some point in the circuit, there is some special logic to split that barrier into single-qubit barriers so that it will not prevent the circuit from separating into multiple pieces. Then, after separation, those barriers are recombined. #625 fixed this code to work with Qiskit 1.2. It is the stuff in transforms.py that has to do with uuids.

garrison commented 2 weeks ago

The test should ideally verify the behavior of the seprate_circuit utility function, which is called inside of the partition_problem function, which itself appears in the first tutorial. And the test should live in teat_transforms.py, alongside other tests of the separate_circuit function.

garrison commented 2 weeks ago

The crux of the problem is that the test suite should fail if the following patch is made to disable (comment out) an important line, but it does not.

diff --git a/circuit_knitting/utils/transforms.py b/circuit_knitting/utils/transforms.py
index 2849d09..715321a 100644
--- a/circuit_knitting/utils/transforms.py
+++ b/circuit_knitting/utils/transforms.py
@@ -135,7 +135,7 @@ def separate_circuit(
             [new_qc.qubits[j] for j in qubits_by_subsystem[label]],
             new_qc.cregs,
         )
-        _combine_barriers(tmp_circ)
+        # _combine_barriers(tmp_circ)
         subcircuits[label] = tmp_circ

     return SeparatedCircuits(subcircuits, qubit_map)