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

change: Remove throw from local task cancellation #856

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions src/braket/tasks/local_quantum_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class LocalQuantumTask(QuantumTask):
"""A quantum task containing the results of a local simulation.

Since this class is instantiated with the results, cancel() and run_async() are unsupported.
Since this class is instantiated with the results, run_async() is unsupported.
"""

def __init__(
Expand All @@ -42,8 +42,12 @@ def id(self) -> str:
return str(self._id)

def cancel(self) -> None:
"""Cancel the quantum task."""
raise NotImplementedError("Cannot cancel completed local task")
"""Attempt to cancel the quantum task.
Copy link
Contributor

@AbeCoull AbeCoull Jan 26, 2024

Choose a reason for hiding this comment

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

nit: if we are always using pass and the task is expected to be complete, attempt has the wrong implication.


Since this class is instantiated with the results, there is nothing to cancel. Attempting
to cancel an already completed task is not an error.
"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I have mixed feelings about using pass here. What would your thoughts be if we instead used a log line indicating local tasks are already complete on instantiation or some better worded statement?


def state(self) -> str:
return "COMPLETED"
Expand Down
1 change: 0 additions & 1 deletion test/unit_tests/braket/tasks/test_local_quantum_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_result():
assert TASK.result() == RESULT


@pytest.mark.xfail(raises=NotImplementedError)
def test_cancel():
TASK.cancel()

Expand Down