Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions cirq-google/cirq_google/engine/engine_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,10 @@ def _get_job_results_v1(self, result: v1.program_pb2.Result) -> Sequence[EngineR
def _get_job_results_v2(self, result: v2.result_pb2.Result) -> Sequence[EngineResult]:
sweep_results = v2.results_from_proto(result)
job_id = self.id()
job_finished = self.update_time()

# Flatten to single list to match to sampler api.
return [
EngineResult.from_result(result, job_id=job_id, job_finished_time=job_finished)
EngineResult.from_result(result, job_id=job_id)
for sweep_result in sweep_results
for result in sweep_result
]
Expand Down
2 changes: 0 additions & 2 deletions cirq-google/cirq_google/engine/engine_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ def test_run_sweep_params_with_unary_rpcs(client):
assert results[i].measurements == {'q': np.array([[0]], dtype='uint8')}
for result in results:
assert result.job_id == job.id()
assert result.job_finished_time is not None
assert results == cirq.read_json(json_text=cirq.to_json(results))

client().create_program_async.assert_called_once()
Expand Down Expand Up @@ -943,7 +942,6 @@ def test_run_sweep_params_with_stream_rpcs(client):
assert results[i].measurements == {'q': np.array([[0]], dtype='uint8')}
for result in results:
assert result.job_id == job.id()
assert result.job_finished_time is not None
assert results == cirq.read_json(json_text=cirq.to_json(results))

client().run_job_over_stream.assert_called_once()
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/engine/engine_program_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_run_delegation(create_job_async, get_results_async):
params=cirq.ParamResolver({'a': 1.0}),
measurements={'q': np.array([[False], [True], [True], [False]], dtype=bool)},
job_id='steve',
job_finished_time=dt,
job_finished_time=None,
)


Expand Down
6 changes: 4 additions & 2 deletions cirq-google/cirq_google/engine/engine_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(
self,
*, # Forces keyword args.
job_id: str,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This resource seems to map to a QuantumResult API resource, but the class doesn't contain the unique identifier for that resource - job_id is only unique within a QuantumProgram parent, which is only unique within a GCP project.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, that's a pre-existing issue, but I could add more fields while I am here. What else should we add, if anything?

Copy link
Collaborator

Choose a reason for hiding this comment

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

project_id and program_id should be included as well and match the values in the parent EngineJob. Feel free to leave as a followup or file a bug since it's out of scope of this change if you aren't going to lazy load the timestamp of the job's completion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I will do that in a follow-up.

job_finished_time: datetime.datetime,
job_finished_time: datetime.datetime | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this used anywhere besides tests and places working around the requirement to set the field? Could we just remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Totally removed.

params: study.ParamResolver | None = None,
measurements: Mapping[str, np.ndarray] | None = None,
records: Mapping[str, np.ndarray] | None = None,
Expand All @@ -60,7 +60,9 @@ def __init__(
self.job_finished_time = job_finished_time

@classmethod
def from_result(cls, result: cirq.Result, *, job_id: str, job_finished_time: datetime.datetime):
def from_result(
cls, result: cirq.Result, *, job_id: str, job_finished_time: datetime.datetime | None = None
):
if isinstance(result, study.ResultDict):
# optimize by using private methods
return cls(
Expand Down