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

Qiskit Algorithms and Qiskit Optimization support for SamplerV2 (QiskitRuntimeService) #213

Open
baniabde2020 opened this issue Dec 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@baniabde2020
Copy link

baniabde2020 commented Dec 1, 2024

Environment

  • Qiskit Algorithms version: 0.3.1
  • Qiskit Optimization version: 0.6.1
  • Python version: 3.9.13
  • Operating system: windows 11

What is happening?

Hi everyone,
I am trying to run a small example of ADMMOptimizer on an ibm quantum machine using QiskitRuntimeService and SamplerV2, I am getting the error bellow.
Any help or suggestions to resolve this issue.
Thank you !

How can we reproduce the issue?

import matplotlib.pyplot as plt
from docplex.mp.model import Model
from qiskit_algorithms import QAOA, NumPyMinimumEigensolver
from qiskit_algorithms.optimizers import COBYLA
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit_optimization.algorithms import CobylaOptimizer, MinimumEigenOptimizer
from qiskit_optimization.algorithms.admm_optimizer import ADMMParameters, ADMMOptimizer
from qiskit_optimization.translators import from_docplex_mp
from qiskit_ibm_runtime import QiskitRuntimeService

# Initialize Qiskit Runtime Service and select backend
service = QiskitRuntimeService()
backend = service.least_busy(min_num_qubits=127)
print(backend)

# Define COBYLA optimizer to handle convex continuous problems
cobyla = CobylaOptimizer()

# Define QAOA via the minimum eigen optimizer
qaoa = MinimumEigenOptimizer(QAOA(sampler=Sampler(mode=backend), optimizer=COBYLA()))

# Exact QUBO solver as classical benchmark
exact = MinimumEigenOptimizer(NumPyMinimumEigensolver())  # to solve QUBOs

# Construct model using DOcplex
mdl = Model("ex6")
v = mdl.binary_var(name="v")
w = mdl.binary_var(name="w")
t = mdl.binary_var(name="t")
u = mdl.continuous_var(name="u")

mdl.minimize(v + w + t + 5 * (u - 2) ** 2)
mdl.add_constraint(v + 2 * w + t + u <= 3, "cons1")
mdl.add_constraint(v + w + t >= 1, "cons2")
mdl.add_constraint(v + w == 1, "cons3")

# Load quadratic program from DOcplex model
qp = from_docplex_mp(mdl)

# Define ADMM parameters
admm_params = ADMMParameters(
    rho_initial=1001, beta=1000, factor_c=900, maxiter=100, three_block=True, tol=1.0e-6
)

# Quantum Solution
# Define QUBO optimizer
qubo_optimizer = qaoa

# Define classical optimizer
convex_optimizer = cobyla

# Initialize ADMM with quantum QUBO optimizer and classical convex optimizer
admm_q = ADMMOptimizer(
    params=admm_params,
    qubo_optimizer=qubo_optimizer,
    continuous_optimizer=convex_optimizer,
)

# Run ADMM to solve problem
result_q = admm_q.solve(qp)
print(result_q.prettyprint())

# Plot residuals
plt.clf()
plt.plot(result_q.state.residuals)
plt.xlabel("Iterations")
plt.ylabel("Residuals")
plt.show()

What should happen?

110 def _call(
    111     self,
    112     circuits: Sequence[int],
   (...)
    115     **run_options,
    116 ) -> _DiagonalEstimatorResult:
--> 117     job = self.sampler.run(
    118         [self._circuits[i] for i in circuits],
    119         parameter_values,
    120         **run_options,
    121     )
    122     sampler_result = job.result()
    123     samples = sampler_result.quasi_dists

TypeError: run() takes 2 positional arguments but 3 were given

Any suggestions?

@jwoehr suggest that Qiskit-algorithms or Qiskit Optimization needs some work to support and be compatible with SamplerV2 and QiskitRuntimeService.

@baniabde2020 baniabde2020 added the bug Something isn't working label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant