Skip to content
This repository was archived by the owner on Jul 12, 2026. It is now read-only.
This repository was archived by the owner on Jul 12, 2026. It is now read-only.

ValueError: The number of qubits of the circuit (156) does not match the number of qubits of the ()-th observable (16). #720

Description

@LairdWilliams

Environment

  • Qiskit Optimization version: 0.7.0
  • Python version: 3.13.11
  • Operating system: 24.04.3 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)

What is happening?

Summary: QAOA Validation check or layout logic fails when using some IBM Quantum Backends.

Concrete example: I have a TSP with 4 nodes, so the op and idealized ansatz circuit will be 16 qubits.
When I check on my own using the pass manager for ibm_fez, I get a circuit with 156 qubits, 140 of which are idle ancillas. So it LOOKS like the logic that preps the op and the ansatz using the pass_manager is correct. Yet I get the error above when I attempt to execute.

How can we reproduce the issue?

Code Summary:

from qiskit_ibm_runtime import SamplerV2 as IBMSampler
...
tsp = Tsp(tsp_graph)
tsp_qp = tsp.to_quadratic_program()
qp2qubo = QuadraticProgramToQubo()
tsp_qubo = qp2qubo.convert(tsp_qp)
qubitOp, offset = tsp_qubo.to_ising()
service = QiskitRuntimeService()
backend = service.least_busy(simulator=False, operational=True)
real_pm = generate_preset_pass_manager(backend = backend, optimization_level = 3)
real_sampler = IBMSampler(mode=backend)
optimizer = COBYLA(maxiter=100)
qaoa = QAOA(sampler=real_sampler, optimizer=optimizer, transpiler=real_pm, reps=7)
result = qaoa.compute_minimum_eigenvalue(qubitOp)  # error occurs here

What should happen?

Circuit should execute. Num qubits of the op and num qubits of the ansatz should be identical.

Any suggestions?

Is SamplingVQE perhaps passing the pre-layout version of the operator to the Estimator primitive when it should be passing the post-layout version? (Line 335 of sampling_veq.py)

(I am very new to this body of code - but a read-through of the code for the relevant methods and some experimentation on my own makes me naively think maybe...)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions