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: Compatibility with Qiskit's run_circuits and CircuitSampler utilities. #19

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion qiskit_rigetti/_qcs_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ def cancel(self) -> None:
raise NotImplementedError("Cancelling jobs is not supported")

def status(self) -> JobStatus:
"""Get the current status of this Job"""
"""Get the current status of this Job

If this job was RUNNING when you called it, this function will block until the job is complete.
"""

if self._status == JobStatus.RUNNING:
# Wait for results _now_ to finish running, otherwise consuming code might wait forever.
self.result()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this effectively ensures that status always returns DONE.... I'm wondering if there is something else in the Qiskit Sampler we can hook into to make sure the job actually starts.

I'll spend a bit of time looking and if I don't find anything I'll approve.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it ensures that status always returns DONE or ERROR, depending.

The right way to fix this is the make status polling truly asynchronous so that results can be processed in the order they complete, not necessarily the order they were submitted. But that will require either complicated thread management or a QCS endpoint for checking status quickly.


return self._status

Expand Down
1 change: 0 additions & 1 deletion tests/test_qcs_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_run(backend: RigettiQCSBackend):
job = execute(circuit, backend, shots=10)

assert job.backend() is backend
assert job.status() == JobStatus.RUNNING
result = job.result()
assert job.status() == JobStatus.DONE
assert result.backend_name == backend.configuration().backend_name
Expand Down
6 changes: 4 additions & 2 deletions tests/test_qcs_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ def test_init__circuit_with_barrier(backend: RigettiQCSBackend, mocker: MockerFi


def test_result(job: RigettiQCSJob):
assert job._status == JobStatus.RUNNING
assert job.status() == JobStatus.DONE, "Checking status did not wait for completion"
assert job._status == JobStatus.DONE

result = job.result()

assert result.date == job.result().date, "Result not cached"

assert job.status() == JobStatus.DONE

assert result.backend_name == "3q-qvm"
assert result.job_id == job.job_id()
assert result.success is True
Expand Down