mapomatic icon indicating copy to clipboard operation
mapomatic copied to clipboard

Dynamic Circuit Error

Open bsiegelwax opened this issue 3 years ago • 5 comments

I have a simple 2-qubit 2-bit dynamic circuit with 1 conditional rotation that executed on ibmq_manila just fine. But, when I add mapomatic I get:

CircuitError: "Unknown classical resource specifier: 'CircuitInstruction(operation=Instruction(name='rz', num_qubits=1, num_clbits=0, params=[-3.141592653589793]), qubits=(Qubit(QuantumRegister(2, 'q'), 1),), clbits=())'."

bsiegelwax avatar Dec 26 '22 15:12 bsiegelwax

Could you please provide an example Python snippet that completely reproduces the issue?

taalexander avatar Dec 26 '22 15:12 taalexander

The entire circuit is:

q = QuantumRegister(1, name="q") c = ClassicalRegister(1, name="c") qc = QuantumCircuit(q, c, name="DVQE") qc.ry(theta, 0) qc.ry(-(pi/2), 0) qc.measure(0, c) with qc.if_test((c, 1)): qc.reset(0) # This line is actually indented. qc.ry(theta, 0) # This line is actually indented. qc.ry(-(pi/2), 0) # This line is actually indented. qc.measure(0, c)

Again, that executes fine without mapomatic. It is transpiled at optimization_level=1. And, this is from this repository:

small_qc = mm.deflate_circuit(qc) # <---- The error is pointing here. layouts = mm.matching_layouts(small_qc, backend) scores = mm.evaluate_layouts(small_qc, layouts, backend) qc = transpile(small_qc, backend, initial_layout=scores[0][0])

bsiegelwax avatar Dec 27 '22 10:12 bsiegelwax

The summary is that mapomatic does not really handle dynamic circuits at present. I am pretty such for the case above it can be, I just need to figure out how to deflate and keep conditional information.

A much more challenging issue is how to score dynamic circuits in general. One could just assume every gate gets executed (worst case) and score that. I am pretty sure that is how the current algorithm would parse it.

nonhermitian avatar Jan 06 '23 14:01 nonhermitian

That is basically what we did inside terra for vf2postlayout when we made it control flow aware: https://github.com/Qiskit/qiskit-terra/commit/a01f738a56827e70e2df917cd4ec0b19f95707db

mtreinish avatar Jan 06 '23 16:01 mtreinish

Yeah, the only bit of work is that it seems that flow control instructions, eg if_else do not follow the same calling format as all the other instructions.

nonhermitian avatar Jan 06 '23 19:01 nonhermitian