Skip to content

Commit

Permalink
rename submit to run_async (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
weinbe58 authored Sep 17, 2023
1 parent aa961cb commit 63d26d4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ calculation = (
.braket.aquila()
)
```
For tasks executed through a remote API, there are three options to run your job. The first is an asynchronous call via `submit`, which will return a `RemoteBatch` object. This object has various methods to `fetch` and or `pull` results from the remote API, along with some other tools that can query the status of the task(s) in this batch. `run` is another method that blocks the script waiting for all the tasks to finish, susequently returning the `RemoteBatch`. The final option is to use the `__call__` method of the `calculation` object for hybrid workflows. The call object is effectively the same as calling `run`. However, specifying the `flatten` option will allow you to call `__call__` with arguments corresponding to the list of strings provided by `flatten`.
For tasks executed through a remote API, there are three options to run your job. The first is an asynchronous call via `run_async`, which will return a `RemoteBatch` object. This is a non-blocking call and `RemoteBatch` acts like a future object. It has various methods to `fetch` and or `pull` results from the remote API, along with some other tools that can query the status of the task(s) in this batch. `run` is another method that blocks the script waiting for all the tasks to finish, susequently returning the `RemoteBatch`. The final option is to use the `__call__` method of the `calculation` object for hybrid workflows. The call object is effectively the same as calling `run`. However, specifying the `flatten` option will allow you to call `__call__` with arguments corresponding to the list of strings provided by `flatten`.

The `RemoteBatch` object can be saved in JSON format using the `save_batch` and reloaded back into Python using the `load_batch` functions. This capability is useful for the asynchronous case, where you can save the batch and load it back later to retrieve the results.

Expand Down Expand Up @@ -224,7 +224,7 @@ program = (

emulator_batch = program.braket.local_emulator().run(1000)

hardware_batch = program.parallelize(20).braket.aquila().submit(1000)
hardware_batch = program.parallelize(20).braket.aquila().run_async(1000)

save_batch("emulator_results.json", emulator_batch)
save_batch("hardware_results.json", hardware_batch)
Expand Down
10 changes: 5 additions & 5 deletions src/bloqade/ir/routine/braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _compile(
return batch

@beartype
def submit(
def run_async(
self,
shots: int,
args: Tuple[LiteralType, ...] = (),
Expand All @@ -91,7 +91,7 @@ def submit(
) -> RemoteBatch:
"""
Compile to a RemoteBatch, which contain
Braket backend specific tasks, and submit to Braket.
Braket backend specific tasks, and run_async to Braket.
Note:
This is async.
Expand Down Expand Up @@ -122,7 +122,7 @@ def run(
) -> RemoteBatch:
"""
Compile to a RemoteBatch, which contain
Braket backend specific tasks, submit to Braket,
Braket backend specific tasks, run_async to Braket,
and wait until the results are coming back.
Note:
Expand All @@ -140,7 +140,7 @@ def run(
"""

batch = self.submit(shots, args, name, shuffle, **kwargs)
batch = self.run_async(shots, args, name, shuffle, **kwargs)
batch.pull()
return batch

Expand All @@ -155,7 +155,7 @@ def __call__(
):
"""
Compile to a RemoteBatch, which contain
Braket backend specific tasks, submit to Braket,
Braket backend specific tasks, run_async to Braket,
and wait until the results are coming back.
Note:
Expand Down
6 changes: 3 additions & 3 deletions src/bloqade/ir/routine/quera.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _compile(
return batch

@beartype
def submit(
def run_async(
self,
shots: int,
args: Tuple[LiteralType, ...] = (),
Expand All @@ -102,7 +102,7 @@ def submit(
"""
Compile to a RemoteBatch, which contain
QuEra backend specific tasks,
and submit through QuEra service.
and run_async through QuEra service.
Args:
shots (int): number of shots
Expand All @@ -127,7 +127,7 @@ def run(
shuffle: bool = False,
**kwargs,
) -> RemoteBatch:
batch = self.submit(shots, args, name, shuffle, **kwargs)
batch = self.run_async(shots, args, name, shuffle, **kwargs)
batch.pull()
return batch

Expand Down
2 changes: 1 addition & 1 deletion tests/test_batch2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
task = prog.quera.mock()


# future = task.submit(shots=100) ## non0-blk
# future = task.run_async(shots=100) ## non0-blk

# future.fetch()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_braket_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def test_error():
.braket_local_simulator(1000)
)
rydberg_densities = simulator_job.submit().report().rydberg_densities()
rydberg_densities = simulator_job.run_async().report().rydberg_densities()
rydberg_densities = (
simulator_job.submit(multiprocessing=True).report().rydberg_densities()
simulator_job.run_async(multiprocessing=True).report().rydberg_densities()
)
# durations for rabi and detuning
Expand All @@ -92,5 +92,5 @@ def test_error():
mis_udg_job = mis_udg_program.batch_assign(final_detuning=np.linspace(0, 80, 81))
hw_job = mis_udg_job.braket_local_simulator(100).submit()
hw_job = mis_udg_job.braket_local_simulator(100).run_async()
"""
2 changes: 1 addition & 1 deletion tests/test_quera_internal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_quera_submit():
.assign(run_time=2.0)
.parallelize(20)
.quera.device(config_file=config_file)
.submit(shots=10)
.run_async(shots=10)
)

bloqade.save_batch("quera_submit.json", batch)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


with tempfile.NamedTemporaryFile() as f:
future = prog.quera.mock(state_file=f.name).submit(shots=100)
future = prog.quera.mock(state_file=f.name).run_async(shots=100)
future.pull()
future2 = future.remove_tasks("Completed")
future2
Expand Down
10 changes: 5 additions & 5 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@


# print(lattice.Square(3).apply(seq).__lattice__)
# print(lattice.Square(3).apply(seq).braket(nshots=1000).submit().report().dataframe)
# print(lattice.Square(3).apply(seq).braket(nshots=1000).run_async().report().dataframe)
# print("bitstring")
# print(lattice.Square(3).apply(seq).braket(nshots=1000).submit().report().bitstring)
# print(lattice.Square(3).apply(seq).braket(nshots=1000).run_async().report().bitstring)

# # pipe interface
# report = (
Expand All @@ -61,7 +61,7 @@
# .apply(Linear(start=1.0, stop="x", duration=3.0))
# .assign(x=10)
# .braket(nshots=1000)
# .submit()
# .run_async()
# .report()
# )

Expand All @@ -73,7 +73,7 @@
# Linear(start=1.0, stop="x", duration=3.0)
# ).location(3).location(4).apply(Linear(start=1.0, stop="x", duration=3.0)).braket(
# nshots=1000
# ).submit()
# ).run_async()

# # start.rydberg.detuning.location(2).location(3)

Expand All @@ -88,7 +88,7 @@
# .apply(Linear(start=1.0, stop="x", duration=3.0))
# .assign(x=1.0)
# .multiplex(10.0).braket(nshots=1000)
# .submit()
# .run_async()
# .report()
# .dataframe.groupby(by=["x"])
# .count()
Expand Down

0 comments on commit 63d26d4

Please sign in to comment.