Qiskit / qiskit-serverless

A programming model for leveraging quantum and classical resources
https://qiskit.github.io/qiskit-serverless/
Apache License 2.0
67 stars 27 forks source link

job.result sometimes returns an empty dict when using save_result #946

Closed caleb-johnson closed 1 year ago

caleb-johnson commented 1 year ago

The following remote program sometimes returns an empty dictionary as the result

# program.py
from quantum_serverless import save_result

my_list = [1, 2, 3, 4]
save_result({"results": my_list})

<Job | b90b6513-4a93-451b-871f-39681b26cbb7> returned an empty dictionary

akihikokuroda commented 1 year ago

This one is difficult to fix :-)

akihikokuroda commented 1 year ago

This seems a concurrency issue between the gateway and the scheduler for the job record.

akihikokuroda commented 1 year ago

I believe what's happening is:

  1. the scheduler gets the job record for the job https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L22
  2. the gateway gets the result request and update the job record with it https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/views.py#L145
  3. the scheduler detects the job status change (PENDING -> SUCCEDED) https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L45
  4. the scheduler updates the job record with the new status -- this override the result field of the job record. https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L57
caleb-johnson commented 1 year ago

I believe what's happening is:

  1. the scheduler gets the job record for the job https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L22
  2. the gateway gets the result request and update the job record with it https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/views.py#L145
  3. the scheduler detects the job status change (PENDING -> SUCCEDED) https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L45
  4. the scheduler updates the job record with the new status -- this override the result field of the job record. https://github.com/Qiskit-Extensions/quantum-serverless/blob/db829650b2b9339d650326a84c30257e4848bcbc/gateway/api/management/commands/update_jobs_statuses.py#L57

Thank you for this explanation!