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

Cut Move instructions do not work on hardware backends unless they support the Reset operation #452

Closed
1 of 3 tasks
garrison opened this issue Nov 14, 2023 · 3 comments · Fixed by #458
Closed
1 of 3 tasks
Assignees
Labels
bug Something isn't working cutting QPD-based circuit cutting code
Milestone

Comments

@garrison
Copy link
Member

garrison commented Nov 14, 2023

Currently, performing wire cutting by using cut versions of the Move operation works only on backends that support the Reset instruction. This includes ibmq_qasm_simulator, but some hardware backends do not currently support this operation.

Here is my proposed plan for dealing with this. Note that, by following these steps, we will be able to support cut Move operations on all backends if qubits are not re-used. However, one must use a backend that supports Reset any time one wishes to re-use qubits.

  • Create and document the use of a transpiler pass that will elide unnecessary Resets. Any number of resets that appear at the beginning of a qubit line can be elided, as the qubit is already in the |0> state. Additionally, any number of resets that appear at the end of a qubit line can be elided as well. Together, this means we can elide all Reset operations necessary for the Move subexperiments, as long as we don't re-use any of the qubits in a subsequent Move instruction. (The current tutorial does re-use qubits, however, which brings me to the following point...) - done, see Remove unnecessary resets in generate_cutting_experiments #458.
  • Swap the content of the wire cutting tutorial and how-to. @caleb-johnson has suggested this before, but I feel that the current issue is overwhelming evidence that we should teach people to use CutWire in the tutorial, and to instead have a how-to guide if people want to cut Move operations directly (and potentially re-use qubits on hardware that supports Reset).
  • Document clearly that re-using qubits for the cut Move instructions is only supported by backends that support the Reset operation. (Or, potentially, the Reset operation could be implemented on any backend that supports dynamic circuits, if we were to add support for this use case.)
@garrison garrison added bug Something isn't working cutting QPD-based circuit cutting code labels Nov 14, 2023
@garrison garrison added this to the 0.6.0 milestone Nov 14, 2023
@garrison
Copy link
Member Author

Create and document the use of a transpiler pass that will elide unnecessary Resets.

If one runs the following block in the tutorial immediately before sending the subexperiments to hardware and is careful to not re-use qubits, then everything works. I am going to open a PR to submit this new transpiler pass to Qiskit.

from qiskit.circuit import Reset
from qiskit.dagcircuit import DAGOutNode
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.passes import RemoveResetInZeroState

class RemoveFinalReset(TransformationPass):
    """Remove reset instruction at the end of a qubit wire."""

    def run(self, dag):
        """Run the RemoveFinalReset pass on `dag`.

        Args:
            dag (DAGCircuit): the DAG to be optimized.

        Returns:
            DAGCircuit: the optimized DAG.
        """
        resets = dag.op_nodes(Reset)
        for reset in resets:
            successor = next(dag.successors(reset))
            if isinstance(successor, DAGOutNode):
                dag.remove_op_node(reset)
        return dag

subexperiments = {
    label: [RemoveResetInZeroState()(RemoveFinalReset()(subexpt)) for subexpt in subexpts]
    for label, subexpts in subexperiments.items()
}

@garrison
Copy link
Member Author

Re-opening until all three check boxes in the top issue are completed.

@garrison
Copy link
Member Author

The third tutorial now works on hardware backends, as the v2 primitives now support dynamic circuits and other circuits with the reset operation.

As for the second point (above), we might still plan to swap the tutorial out to use CutWire in the future, but that is no longer essential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cutting QPD-based circuit cutting code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant