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

Update cancel method #1038

Closed
wants to merge 4 commits into from
Closed
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
1 change: 0 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ on:
workflow_dispatch:
jobs:
integration-tests:
if: github.repository_owner == 'Qiskit'
name: Run integration tests - ${{ matrix.environment }}
runs-on: ${{ matrix.os }}
strategy:
Expand Down
7 changes: 6 additions & 1 deletion qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ def cancel(self) -> None:
raise RuntimeInvalidStateError(f"Job cannot be cancelled: {ex}") from None
raise IBMRuntimeError(f"Failed to cancel job: {ex}") from None
self.cancel_result_streaming()
self._status = JobStatus.CANCELLED
time.sleep(2) # wait for job status to update
self.status()
if self._status != JobStatus.CANCELLED:
raise RuntimeInvalidStateError(
f"Failed to cancel job: {self._job_id} has status {self._status}"
)
Copy link
Member Author

Choose a reason for hiding this comment

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

@merav-aharoni thoughts on this approach? Instead of manually setting this status to cancelled, we query the status from the server to check the actual status

Copy link
Member Author

Choose a reason for hiding this comment

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

But i'm not sure if there's a better way - I don't like having to make another api call just to handle this relatively rare edge case where the job runs too quickly and cannot be cancelled.


def backend(self, timeout: Optional[float] = None) -> Optional[Backend]:
"""Return the backend where this job was executed. Retrieve data again if backend is None.
Expand Down