File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
cirq-google/cirq_google/serialization Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -689,9 +689,11 @@ def _deserialize_gate_op(
689689 )
690690 op = cirq .WaitGate (duration = cirq .Duration (nanos = total_nanos or 0.0 ))(* qubits )
691691 elif which_gate_type == 'resetgate' :
692- dimensions = arg_func_langs .arg_from_proto (
693- operation_proto .resetgate .arguments .get ('dimension' , 2 )
694- )
692+ dimensions_proto = operation_proto .resetgate .arguments .get ('dimension' , None )
693+ if dimensions_proto is not None :
694+ dimensions = arg_func_langs .arg_from_proto (dimensions_proto )
695+ else :
696+ dimensions = 2
695697 if not isinstance (dimensions , int ):
696698 # This should always be int, if serialized from cirq.
697699 raise ValueError (f"dimensions { dimensions } for ResetChannel must be an integer!" )
Original file line number Diff line number Diff line change @@ -1045,6 +1045,24 @@ def test_reset_gate_with_improper_argument():
10451045 serializer .deserialize (circuit_proto )
10461046
10471047
1048+ def test_reset_gate_with_no_dimension ():
1049+ serializer = cg .CircuitSerializer ()
1050+
1051+ op = v2 .program_pb2 .Operation ()
1052+ op .resetgate .SetInParent ()
1053+ op .qubit_constant_index .append (0 )
1054+ circuit_proto = v2 .program_pb2 .Program (
1055+ language = v2 .program_pb2 .Language (arg_function_language = 'exp' , gate_set = _SERIALIZER_NAME ),
1056+ circuit = v2 .program_pb2 .Circuit (
1057+ scheduling_strategy = v2 .program_pb2 .Circuit .MOMENT_BY_MOMENT ,
1058+ moments = [v2 .program_pb2 .Moment (operations = [op ])],
1059+ ),
1060+ constants = [v2 .program_pb2 .Constant (qubit = v2 .program_pb2 .Qubit (id = '1_2' ))],
1061+ )
1062+ reset_circuit = serializer .deserialize (circuit_proto )
1063+ assert reset_circuit == cirq .Circuit (cirq .R (cirq .q (1 , 2 )))
1064+
1065+
10481066def test_stimcirq_gates ():
10491067 stimcirq = pytest .importorskip ("stimcirq" )
10501068 serializer = cg .CircuitSerializer ()
You can’t perform that action at this time.
0 commit comments