Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
135 stars 149 forks source link

simulator_stabilizer rejecting circuits containing cx gates #1475

Open cqc-melf opened 4 months ago

cqc-melf commented 4 months ago

Environment

What is happening?

This error shows up when updating qiskit-ibm-runtime from 0.19 to 0.20 or 0.21 (So the error is only showing up with qiskit-ibm-runtime==0.20 and qiskit-ibm-runtime==0.21

simulator_stabilizer is rejecting circuits containing cx gates, the error messages shown is: qiskit.transpiler.exceptions.TranspilerError: "The number of qubits for Instruction(name='cx', num_qubits=2, num_clbits=0, params=[]) does not match the number of qubits in the properties dictionary: (0,)"

How can we reproduce the issue?

    num_qubits = 2
    qc = QuantumCircuit(num_qubits)
    qc.h(0)
    qc.sx(1)
    qc.cx(0, 1)
    qc.measure_all()

    _service = QiskitRuntimeService(
        channel="ibm_quantum",
        instance="ibm-q/open/main",
        token="<insert your token>",
    )
    _session = Session(service=_service, backend="simulator_stabilizer")

    sampler = Sampler(session=_session)
    job = sampler.run(circuits=qc)
    job.result()

What should happen?

The circuit should run and no error should be shown

Any suggestions?

No response

1ucian0 commented 4 months ago

Transferring this to Qiskit/qiskit-ibm-runtime

frankharkins commented 4 months ago

This seems to be a problem in the coupling map returned for simulator_stabilizer:

response = requests.request(
    "GET",
    "https://api.quantum-computing.ibm.com/runtime/backends/simulator_stabilizer/configuration",
    headers={
        "Accept": "application/json",
        "Authorization": "Bearer <token>"
    },
)
response.json()["gates"][0]
{'coupling_map': [[0], [1], [2], [3], [4]],
 'name': 'cx',
 'parameters': [],
 'qasm_def': 'gate cx c,t { CX c,t; }',
 'conditional': True,
 'description': 'Two-qubit Controlled-NOT gate'}

The following code passes this map to the transpiler which then raises the error.

https://github.com/Qiskit/qiskit-ibm-runtime/blob/50797a909f376a5ab051b4cefd787ced7a2160e0/qiskit_ibm_runtime/utils/backend_converter.py#L117-L124

It seems each element in the coupling map should have two elements (e.g. [[0, 1], [1, 2] ... ]) or the gate shouldn't have a coupling map attribute. Since the stabilizer can go up to 5000 qubits and has (I believe) all-to-all connectivity, the latter is probably best.