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

Imported transpiled circuit has different layout #28

Closed
jyu00 opened this issue Mar 11, 2024 · 3 comments · Fixed by #30
Closed

Imported transpiled circuit has different layout #28

jyu00 opened this issue Mar 11, 2024 · 3 comments · Fixed by #30

Comments

@jyu00
Copy link

jyu00 commented Mar 11, 2024

Qiskit Runtime primitives now requires ISA circuits. But running an OpenQASM3 circuit fails due to the importer not setting the qubit mapping correctly.

Code to recreate:

from qiskit.circuit.random import random_circuit
from qiskit import QuantumCircuit, qasm2, qasm3, transpile
from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService()
backend = service.backend("ibm_peekskill")
 
random_circ = random_circuit(5, depth=3, seed=42).decompose(reps=3)
random_circ.measure_all()
transpiled = transpile(random_circ, backend=backend)

# Export to QASM3
qasm = qasm3.dumps(random_circ).replace("\n", " ")
for line in qasm.split("\n"):
    if "ecr" in line:
        print(line)

shows the ecr gate was applied to the physical qubits:

ecr $13, $12;
ecr $13, $12;
ecr $12, $10;
ecr $11, $14;
ecr $14, $13;
ecr $14, $13;
ecr $14, $13;
ecr $14, $13;

But if I re-import that, circuit.data uses qubits 0-5:

from qiskit.qasm3 import loads as qasm3_loads

loaded_circuit = qasm3_loads(qasm)

for instruction in loaded_circuit.data:
    name = instruction.operation.name
    if name == "ecr":
        qargs = tuple(circuit.find_bit(x).index for x in instruction.qubits)
        print(f"Found instruction {name} on qubits {qargs} ")

shows

Found instruction ecr on qubits (3, 2) 
Found instruction ecr on qubits (3, 2) 
Found instruction ecr on qubits (2, 0) 
Found instruction ecr on qubits (1, 4) 
Found instruction ecr on qubits (4, 3) 
Found instruction ecr on qubits (4, 3) 
Found instruction ecr on qubits (4, 3) 
Found instruction ecr on qubits (4, 3) 
@johannesgreiner
Copy link

johannesgreiner commented Mar 12, 2024

This affects API-only users sending qasm to our (Runtime) APIs. The cloud transpilation service is also affected, and returns non-ISA circuits for some circuits & users. Please do assign priority to this issue in users' interest.

@jakelishman
Copy link
Member

I'll look into this. We will most likely have to add an extra keyword argument to the importer functions, because OpenQASM 3 itself simply doesn't have enough information to fully represent things - say, in the example program at the top, the circuit uses only as high as $14, but the hardware has an actual number of qubits it wants to be present in the circuit more like 127.

@jakelishman
Copy link
Member

New keyword arguments (to make the full-width circuit) are new features, and they should wait until Qiskit 1.1 (May), but what we can do in the interim is fix the bug where the importer isn't making the output circuit at least as wide as the highest physical qubit used, and then it should be an easy change for IBM primitives to add on extra dummy qubits to make it full width (if they need circuits to contain them).

I think that's probably the least risky path forwards here, for the timescales.

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 a pull request may close this issue.

3 participants