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

Fix code in threading example #1568

Closed
abbycross opened this issue Jun 17, 2024 · 0 comments · Fixed by #1571
Closed

Fix code in threading example #1568

abbycross opened this issue Jun 17, 2024 · 0 comments · Fixed by #1571

Comments

@abbycross
Copy link
Collaborator

@LenaPer found that the code example is not working as expected in the https://docs.quantum.ibm.com/run/run-jobs-in-session#run-two-vqe-algorithms-in-a-session-by-using-threading section. @jyu00 has provided updated code:

from concurrent.futures import ThreadPoolExecutor
from qiskit_ibm_runtime import EstimatorV2 as Estimator

def minimize_thread(estimator, method):
    return minimize(cost_func, x0, args=(ansatz, hamiltonian, estimator), method=method)

with Session(backend=backend), ThreadPoolExecutor() as executor:
    estimator1 = Estimator()
    estimator2 = Estimator()

    # Use different tags to differentiate the jobs.
    estimator1.options.environment.job_tags = ["cobyla"]
    estimator2.options.environment.job_tags = ["nelder-mead"]

    # Submit the two workloads.
    cobyla_future = executor.submit(minimize_thread, estimator1, "cobyla")
    nelder_mead_future = executor.submit(minimize_thread, estimator2, "nelder-mead")

    # Get workload results.
    cobyla_result = cobyla_future.result()
    nelder_mead_result = nelder_mead_future.result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant