Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 6 additions & 0 deletions cirq-google/cirq_google/api/v2/program.proto
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ message Operation {
IdentityGate identitygate = 19;
HPowGate hpowgate = 20;
SingleQubitCliffordGate singlequbitcliffordgate = 21;
ResetGate resetgate = 24;
}

// Map from the argument name to the Argument needed to fully specify
Expand Down Expand Up @@ -617,3 +618,8 @@ message IdentityGate {
message HPowGate {
FloatArg exponent = 1;
}

message ResetGate {
string reset_type = 1;
Comment thread
pavoljuhas marked this conversation as resolved.
map<string, Arg> arguments = 2;
}
170 changes: 88 additions & 82 deletions cirq-google/cirq_google/api/v2/program_pb2.py

Large diffs are not rendered by default.

47 changes: 44 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.

10 changes: 10 additions & 0 deletions cirq-google/cirq_google/serialization/circuit_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ def _serialize_gate_op(
arg_func_langs.float_arg_to_proto(
gate.duration.total_nanos(), out=msg.waitgate.duration_nanos
)
elif isinstance(gate, cirq.ResetChannel):
arg_func_langs.arg_to_proto(gate.dimension, out=msg.resetgate.arguments['dimension'])
elif isinstance(gate, CouplerPulse):
arg_func_langs.float_arg_to_proto(
gate.hold_time.total_picos(), out=msg.couplerpulsegate.hold_time_ps
Expand Down Expand Up @@ -648,6 +650,14 @@ def _deserialize_gate_op(
operation_proto.waitgate.duration_nanos, required_arg_name=None
)
op = cirq.WaitGate(duration=cirq.Duration(nanos=total_nanos or 0.0))(*qubits)
elif which_gate_type == 'resetgate':
dimensions = arg_func_langs.arg_from_proto(
operation_proto.resetgate.arguments.get('dimension', 2)
)
assert isinstance(
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: prefer not to use assert in non test files

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.

dimensions, int
), f"dimensions {dimensions} for ResetChannel must be an integer!"
op = cirq.ResetChannel(dimension=dimensions)(*qubits)
elif which_gate_type == 'internalgate':
op = arg_func_langs.internal_gate_from_proto(operation_proto.internalgate)(*qubits)
elif which_gate_type == 'couplerpulsegate':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ def circuit_proto(json: Dict, qubits: List[str]):
{'waitgate': {'duration_nanos': {'float_value': 15}}, 'qubit_constant_index': [0]}
),
),
(
cirq.R(Q0),
op_proto(
{
'resetgate': {'arguments': {'dimension': {'arg_value': {'float_value': 2}}}},
'qubit_constant_index': [0],
}
),
),
(
cirq.MeasurementGate(num_qubits=2, key='iron', invert_mask=(True, False))(Q0, Q1),
op_proto(
Expand Down