Skip to content

Commit d3b4d83

Browse files
committed
Fix typecheck
1 parent 8cdb293 commit d3b4d83

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cirq-google/cirq_google/serialization/circuit_serializer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ def _deserialize_gate_op(
750750
p = arg_func_langs.float_arg_from_proto(
751751
operation_proto.noisechannel.depolarizingchannel.probability
752752
)
753+
if not isinstance(p, float):
754+
raise ValueError(
755+
f"Depolarizing noise probability {p} " "cannot be symbol or None"
756+
) # pragma: nocover
753757
op = cirq.DepolarizingChannel(p=p)(*qubits)
754758
elif which_channel_type == 'randomgatechannel':
755759
p = arg_func_langs.float_arg_from_proto(
@@ -760,12 +764,16 @@ def _deserialize_gate_op(
760764
constants=constants,
761765
deserialized_constants=deserialized_constants,
762766
)
767+
if sub_gate is None:
768+
raise ValueError(
769+
"Not a valid gate for RandomGateChannel: " f"{operation_proto}"
770+
) # pragma: nocover
763771
op = cirq.RandomGateChannel(probability=p, sub_gate=sub_gate.gate)(*qubits)
764772
else:
765773
raise ValueError(
766774
f'Unsupported serialized noise channel with type "{which_channel_type}".'
767775
f'\n\noperation_proto:\n{operation_proto}'
768-
)
776+
) # pragma: nocover
769777
else:
770778
raise ValueError(
771779
f'Unsupported serialized gate with type "{which_gate_type}".'

0 commit comments

Comments
 (0)