You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Environment
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?
What should happen?
Any suggestions?
@jwoehr suggest that Qiskit-algorithms or Qiskit Optimization needs some work to support and be compatible with SamplerV2 and QiskitRuntimeService.
The text was updated successfully, but these errors were encountered: