File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
cirq-google/cirq_google/api/v2 Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 1414
1515from __future__ import annotations
1616
17+ import numbers
1718from typing import Any , Callable , cast , TYPE_CHECKING
1819
1920import sympy
@@ -31,10 +32,10 @@ def _build_sweep_const(value: Any) -> run_context_pb2.ConstValue:
3132 """Build the sweep const message from a value."""
3233 if value is None :
3334 return run_context_pb2 .ConstValue (is_none = True )
34- elif isinstance (value , float ):
35- return run_context_pb2 .ConstValue (float_value = value )
36- elif isinstance (value , int ):
37- return run_context_pb2 .ConstValue (int_value = value )
35+ elif isinstance (value , numbers . Integral ):
36+ return run_context_pb2 .ConstValue (int_value = int ( value ) )
37+ elif isinstance (value , numbers . Real ):
38+ return run_context_pb2 .ConstValue (float_value = float ( value ) )
3839 elif isinstance (value , str ):
3940 return run_context_pb2 .ConstValue (string_value = value )
4041 elif isinstance (value , tunits .Value ):
Original file line number Diff line number Diff line change 1818from copy import deepcopy
1919from typing import Iterator
2020
21+ import numpy as np
2122import pytest
2223import sympy
2324import tunits
@@ -418,3 +419,9 @@ def test_tunits_round_trip(sweep):
418419 msg = v2 .sweep_to_proto (sweep )
419420 recovered = v2 .sweep_from_proto (msg )
420421 assert sweep == recovered
422+
423+
424+ @pytest .mark .parametrize ('value' , [np .float32 (3.14 ), np .int64 (5 )])
425+ def test_const_sweep_with_numpy_types_roundtrip (value ):
426+ sweep = cirq .Points ('const' , [value ])
427+ assert v2 .sweep_from_proto (v2 .sweep_to_proto (sweep )) == sweep
You can’t perform that action at this time.
0 commit comments