Skip to content

[WIP] Add a function to make conditionals twirlable#68

Open
TsafrirA wants to merge 2 commits intomainfrom
ta-analyze-if-else
Open

[WIP] Add a function to make conditionals twirlable#68
TsafrirA wants to merge 2 commits intomainfrom
ta-analyze-if-else

Conversation

@TsafrirA
Copy link
Collaborator

Related Issues

#27
#29

Summary

This WIP PR adds a function which analyzes conditionals, and (when possible) creates a twirlable form of them for both left\right dressing.

Details and comments

This conditional cannot be twirled:

from qiskit import QuantumCircuit

qc = QuantumCircuit(2,2)
with qc.if_test((qc.clbits[0], 1)) as _else:
    qc.sx(1)
    qc.cx(0, 1)
    qc.h(0)
with _else:
    qc.sx(0)
    qc.x(1)
instr = qc[0]
qc.draw("mpl")
image

Using the function we can find a twirlable form for left dressing:

from samplomatic.transpiler.passes.analyze_if_else import analyze_if_else_instruction
left_dressing_result, right_dressing_result = analyze_if_else_instruction(instr)

left_dressing = qc.copy_empty_like()
left_dressing.append(left_dressing_result.instr)
for instr in left_dressing_result.additional_1q_ops:
    left_dressing.append(instr)

left_dressing.draw("mpl")
image

The same should work for right dressing, but there is a bug marked by a TODO in the code.

Some things to think about:

  • The inversed operations might not be in the basis set and another transpilation will be needed. Should we add the original pass manager as an input to this function?
  • How would something like this fit into the boxing pass manager?

@TsafrirA TsafrirA requested a review from a team as a code owner August 18, 2025 09:21
@ihincks
Copy link
Collaborator

ihincks commented Aug 20, 2025

I think we should put developing conditional support on hold until we've done some refactoring and strategizing to simplify the code base. I'm finding it increasingly difficult to reason about the build process.

@TsafrirA
Copy link
Collaborator Author

@ihincks

I think we should put developing conditional support on hold until we've done some refactoring and strategizing to simplify the code base. I'm finding it increasingly difficult to reason about the build process.

I agree with the general idea, but this particular PR doesn't involve the build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants