Skip to content

Commit

Permalink
Fixed failing test from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
edyounis committed Aug 28, 2024
1 parent 7246e37 commit 4749049
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bqskit/passes/control/paralleldo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
self,
pass_sequences: Iterable[WorkflowLike],
less_than: Callable[[Circuit, Circuit], bool],
pick_fisrt: bool = False,
pick_first: bool = False,
) -> None:
"""
Construct a ParallelDo.
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(

self.workflows = [Workflow(p) for p in pass_sequences]
self.less_than = less_than
self.pick_first = pick_fisrt
self.pick_first = pick_first

if len(self.workflows) == 0:
raise ValueError('Must specify at least one workflow.')
Expand Down
6 changes: 5 additions & 1 deletion bqskit/runtime/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ def cancel(self) -> None:
# it is likely a blanket try/accept catching the
# error used to stop the coroutine, preventing
# it from stopping correctly.
self.coro.close()
try:
self.coro.close()
except ValueError:
# Coroutine is running and cannot be closed.
pass
else:
raise RuntimeError('Task was cancelled with None coroutine.')

Expand Down
8 changes: 4 additions & 4 deletions tests/passes/control/test_paralleldo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ async def run(self, circuit: Circuit, data: PassData) -> None:
data['key'] = '1'


class Sleep3Pass(BasePass):
class Sleep9Pass(BasePass):
async def run(self, circuit: Circuit, data: PassData) -> None:
circuit.append_gate(ZGate(), 0)
time.sleep(0.3)
data['key'] = '3'
time.sleep(0.9)
data['key'] = '9'


def pick_z(c1: Circuit, c2: Circuit) -> bool:
Expand All @@ -66,7 +66,7 @@ def test_parallel_do_no_passes() -> None:


def test_parallel_do_pick_first(compiler: Compiler) -> None:
passes: list[list[BasePass]] = [[Sleep3Pass()], [Sleep1Pass()]]
passes: list[list[BasePass]] = [[Sleep9Pass()], [Sleep1Pass()]]
pd_pass = ParallelDo(passes, pick_z, True)
_, data = compiler.compile(Circuit(1), pd_pass, True)
assert data['key'] == '1'

0 comments on commit 4749049

Please sign in to comment.