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

Job operations are not parallelizable #300

Open
george-moussa opened this issue Apr 21, 2022 · 3 comments
Open

Job operations are not parallelizable #300

george-moussa opened this issue Apr 21, 2022 · 3 comments

Comments

@george-moussa
Copy link
Contributor

I'm trying to submit and process results of multiple jobs in parallel but I'm noticing that, in many cases, jobs are submitted sequentially.

import datetime
import imp
from multiprocessing import Pool
from azure.quantum import Workspace
from azure.quantum.optimization import Problem, ProblemType, Term
from azure.quantum.target.toshiba import SimulatedBifurcationMachine
import logging


def create_problem():
    problem = Problem('Test_Problem', problem_type=ProblemType.pubo)
    problem.add_terms([
        Term(c=1, indices=[]),
        Term(c=2, indices=[1, 2]),
        Term(c=-3, indices=[1, 2]),
        Term(c=1, indices=[0, 2])
    ])
    return problem


def exec_job(no):
    workspace = Workspace (
        resource_id = "<workspace-id>",
        location= "<location>"
    )

    problem = create_problem()
    solver = SimulatedBifurcationMachine(workspace, loops=0, timeout=10)
    print(str(datetime.datetime.utcnow()), "\t[%d] solver.submit() start" % no)
    job = solver.submit(problem)
    print(str(datetime.datetime.utcnow()), "\t[%d] job.id=%s" % (no, str(job.id)))

    print(str(datetime.datetime.utcnow()), "\t[%d] job.get_results() start" % no)
    result = job.get_results()
    print(str(datetime.datetime.utcnow()), "\t[%d] job.details=%s" % (no, str(job.details)))


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    njobs = 2
    with Pool(processes=njobs) as pool:
        pool.map(func=exec_job, iterable=range(njobs))

For the above, output is:
2022-04-21 18:40:23.466530 [0] solver.submit() start
2022-04-21 18:40:23.542727 [1] solver.submit() start
2022-04-21 18:40:28.752803 [1] job.id=810bc3bb-c1a2-11ec-baa1-b831b575aea6
2022-04-21 18:40:28.752803 [1] job.get_results() start
..........2022-04-21 18:40:52.826348 [1] job.details={..........}
2022-04-21 18:44:19.108243 [0] job.id=81018a8e-c1a2-11ec-adf4-b831b575aea6
2022-04-21 18:44:19.109211 [0] job.get_results() start
..........2022-04-21 18:44:42.799796 [0] job.details={..............}

You can see that job 1 was submitted and awaited while job 0 hasn't been submitted at the same time and was done 4 mins after the first job.

@guenp
Copy link
Contributor

guenp commented Apr 21, 2022

Another solution to submitting multiple jobs in parallel would be through async i/o, see #94.

@anpaz
Copy link
Member

anpaz commented May 14, 2022

Unfortunately, I'm seeing the same problem when using the aio library.
There seems to be some deadlock happening on a low-level http library. I have opened a ticket with the azure-sdk team to get their help: Azure/azure-sdk-for-python#24443

@anpaz
Copy link
Member

anpaz commented Jul 5, 2022

More analysis suggests this is a service problem, which we're investigating and might have a solution soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants