Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions cirq-google/cirq_google/api/v2/program.proto
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ message ArgValue {
RepeatedDouble double_values = 6;
RepeatedString string_values = 7;
tunits.Value value_with_unit = 8;
bool bool_value = 9;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: can we move this field next to bool_values for better discoverability in the future. (I'm aware this convention hasn't been done before.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think that's a good idea. I think it's generally better to keep things in order of field id unless there's a really good reason. Otherwise, it gets more confusing to add fields.

}
}

Expand Down
108 changes: 54 additions & 54 deletions cirq-google/cirq_google/api/v2/program_pb2.py

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions cirq-google/cirq_google/api/v2/program_pb2.pyi

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

6 changes: 5 additions & 1 deletion cirq-google/cirq_google/serialization/arg_func_langs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def arg_to_proto(
"""
msg = v2.program_pb2.Arg() if out is None else out

if isinstance(value, FLOAT_TYPES):
if isinstance(value, bool):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

on line 146, there is a check for np.bool_, should that be included in this check?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

msg.arg_value.bool_value = value
elif isinstance(value, FLOAT_TYPES):
msg.arg_value.float_value = float(value)
elif isinstance(value, str):
msg.arg_value.string_value = value
Expand Down Expand Up @@ -274,6 +276,8 @@ def arg_from_proto(
if math.ceil(result) == math.floor(result):
result = int(result)
return result
if which_val == 'bool_value':
return bool(arg_value.bool_value)
if which_val == 'bool_values':
return list(arg_value.bool_values.values)
if which_val == 'string_value':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _json_format_kwargs() -> Dict[str, bool]:
(1.0, {'arg_value': {'float_value': 1.0}}),
(1, {'arg_value': {'float_value': 1.0}}),
('abc', {'arg_value': {'string_value': 'abc'}}),
(True, {'arg_value': {'bool_value': True}}),
([True, False], {'arg_value': {'bool_values': {'values': [True, False]}}}),
([42.9, 3.14], {'arg_value': {'double_values': {'values': [42.9, 3.14]}}}),
([3, 8], {'arg_value': {'int64_values': {'values': ['3', '8']}}}),
Expand Down