Skip to content

Commit

Permalink
json serialize SharedRuntimeInfo.device (quantumlib#5746)
Browse files Browse the repository at this point in the history
Include the SharedRuntimeInfo.device field in the JSON dump and
update the affected test data files.

Part of quantumlib#4699 and quantumlib#5050.
  • Loading branch information
pavoljuhas authored and rht committed May 1, 2023
1 parent 4b39772 commit cf492ce
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"shared_runtime_info": {
"cirq_type": "cirq.google.SharedRuntimeInfo",
"run_id": "my run",
"device": null,
"run_start_time": {
"cirq_type": "datetime.datetime",
"timestamp": 1651091275.571572
Expand Down Expand Up @@ -146,4 +147,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cirq_type": "cirq.google.SharedRuntimeInfo",
"run_id": "my run",
"device": null,
"run_start_time": {
"cirq_type": "datetime.datetime",
"timestamp": 1651091275.571572
Expand All @@ -9,4 +10,4 @@
"cirq_type": "datetime.datetime",
"timestamp": 1651092475.571585
}
}
}
5 changes: 1 addition & 4 deletions cirq-google/cirq_google/workflow/quantum_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ def _json_namespace_(cls) -> str:
return 'cirq.google'

def _json_dict_(self) -> Dict[str, Any]:
d = dataclass_json_dict(self)
# TODO (gh-4699): serialize `device` as well once SerializableDevice is serializable.
del d['device']
return d
return dataclass_json_dict(self)

def __repr__(self) -> str:
return _compat.dataclass_repr(self, namespace='cirq_google')
Expand Down
2 changes: 0 additions & 2 deletions cirq-google/cirq_google/workflow/quantum_runtime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ def test_execute(tmpdir, rt_config):
run_id=run_id, base_data_dir=tmpdir
).load(base_data_dir=tmpdir)

# TODO(gh-4699): Don't null-out device once it's serializable.
assert isinstance(returned_exegroup_result.shared_runtime_info.device, cirq.Device)
returned_exegroup_result.shared_runtime_info.device = None

assert returned_exegroup_result == exegroup_result
assert manual_exegroup_result == exegroup_result
Expand Down

0 comments on commit cf492ce

Please sign in to comment.