Skip to content

Commit c40e01d

Browse files
authored
Make program.run() return an EngineJob so it's consistent with program.run_sweep() (#8048)
Internal request by @eliottrosenberg to have program.run() return an EngineJob, rather than having the function wait for the EngineJob to complete before returning. This interface makes it consistent with existing program.run_sweep() Fixes b/495930398
1 parent fdf7e50 commit c40e01d

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

cirq-google/cirq_google/engine/engine_program.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def run_async(
147147
repetitions: int = 1,
148148
description: str | None = None,
149149
labels: dict[str, str] | None = None,
150-
) -> cirq.Result:
150+
) -> engine_job.EngineJob:
151151
"""Runs the supplied Circuit via Quantum Engine.
152152
153153
Args:
@@ -171,15 +171,15 @@ async def run_async(
171171
labels: Optional set of labels to set on the job.
172172
173173
Returns:
174-
A single Result for this run.
174+
An EngineJob. If this is iterated over it yields one EngineResult.
175175
176176
Raises:
177177
ValueError: If a processor id hasn't been specified to run the job
178178
ValueError: If only one of `run_name` and `device_config_name` are specified.
179179
ValueError: If either `run_name` and `device_config_name` are set but
180180
`processor_id` is empty.
181181
"""
182-
job = await self.run_sweep_async(
182+
return await self.run_sweep_async(
183183
job_id=job_id,
184184
params=[param_resolver],
185185
repetitions=repetitions,
@@ -190,8 +190,6 @@ async def run_async(
190190
snapshot_id=snapshot_id,
191191
device_config_name=device_config_name,
192192
)
193-
results = await job.results_async()
194-
return results[0]
195193

196194
run = duet.sync(run_async)
197195

cirq-google/cirq_google/engine/engine_program_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_run_delegation(create_job_async, get_results_async):
139139

140140
program = cg.EngineProgram('a', 'b', EngineContext())
141141
param_resolver = cirq.ParamResolver({})
142-
results = program.run(
142+
job = program.run(
143143
job_id='steve',
144144
repetitions=10,
145145
param_resolver=param_resolver,
@@ -148,7 +148,9 @@ def test_run_delegation(create_job_async, get_results_async):
148148
device_config_name="config",
149149
)
150150

151-
assert results == cg.EngineResult(
151+
(result,) = job
152+
153+
assert result == cg.EngineResult(
152154
params=cirq.ParamResolver({'a': 1.0}),
153155
measurements={'q': np.array([[False], [True], [True], [False]], dtype=bool)},
154156
job_id='steve',

cirq-google/cirq_google/engine/engine_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def test_run_multiple_times(client):
612612
param_resolver=cirq.ParamResolver({'a': 1}),
613613
run_name="run",
614614
device_config_name="config_alias",
615-
)
615+
).results()
616616
run_context = v2.run_context_pb2.RunContext()
617617
client().create_job_async.call_args[1]['run_context'].Unpack(run_context)
618618
sweeps1 = run_context.parameter_sweeps

0 commit comments

Comments
 (0)