Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make device parameter units/idx optional #6264

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions cirq-google/cirq_google/api/v2/run_context.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ message DeviceParameter {
repeated string path = 1;

// If the value is an array, the index of the array to change.
int64 idx = 2;
optional int64 idx = 2;

// String representation of the units, if any.
// Examples: "GHz", "ns", etc.
string units = 3;
optional string units = 3;

// Note that the device parameter values will be populated
// by the sweep values themselves.
Expand Down
16 changes: 8 additions & 8 deletions cirq-google/cirq_google/api/v2/run_context_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions cirq-google/cirq_google/api/v2/run_context_pb2.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion cirq-google/cirq_google/api/v2/sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def sweep_from_proto(msg: run_context_pb2.Sweep) -> cirq.Sweep:
key = msg.single_sweep.parameter_key
if msg.single_sweep.HasField("parameter"):
metadata = DeviceParameter(
path=msg.single_sweep.parameter.path, idx=msg.single_sweep.parameter.idx
path=msg.single_sweep.parameter.path,
idx=msg.single_sweep.parameter.idx
if msg.single_sweep.parameter.HasField("idx")
else None,
units=msg.single_sweep.parameter.units
if msg.single_sweep.parameter.HasField("units")
else None,
)
else:
metadata = None
Expand Down
7 changes: 7 additions & 0 deletions cirq-google/cirq_google/api/v2/sweeps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def _values(self) -> Iterator[float]:
[1, 1.5, 2, 2.5, 3],
metadata=DeviceParameter(path=['path', 'to', 'parameter'], idx=2, units='GHz'),
),
cirq.Points(
'b',
[1, 1.5, 2, 2.5, 3],
metadata=DeviceParameter(path=['path', 'to', 'parameter'], idx=None),
),
cirq.Linspace('a', 0, 1, 5) * cirq.Linspace('b', 0, 1, 5),
cirq.Points('a', [1, 2, 3]) + cirq.Linspace('b', 0, 1, 3),
(
Expand All @@ -69,6 +74,8 @@ def test_sweep_to_proto_roundtrip(sweep):
msg = v2.sweep_to_proto(sweep)
deserialized = v2.sweep_from_proto(msg)
assert deserialized == sweep
# Check that metadata is the same, if it exists.
assert getattr(deserialized, 'metadata', None) == getattr(sweep, 'metadata', None)


def test_sweep_to_proto_linspace():
Expand Down