Skip to content

Commit 5a81b3d

Browse files
Remove previously deprecated fields in cirq_google proto (#7183)
* Remove previously deprecated fields in cirq_google proto - Removes schedule (not used in 5+ years) - Removes gate and args (not used since v2.5, 3+ years) - Removes checks on gate set and language. - Removes tests that use the above. * Take care of deprecated usage in test. * Another broken test. * Remove another test * Remove engine test with bad gateset * Put back test. * Add back lint issue. --------- Co-authored-by: Pavol Juhas <[email protected]>
1 parent 2ad1b70 commit 5a81b3d

File tree

8 files changed

+140
-361
lines changed

8 files changed

+140
-361
lines changed

cirq-google/cirq_google/api/v2/program.proto

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ message Program {
1919
// moment having a set of gates that act on disjoint qubits. Circuits don't
2020
// have absolute times for their operations (gates acting on qubits).
2121
Circuit circuit = 2;
22-
23-
// Schedules are a list of operations (gates acting on qubits) that specify
24-
// absolute start times for the operations.
25-
Schedule schedule = 3;
2622
}
2723

24+
// Previously deprecated field. Do not use.
25+
reserved 3;
26+
2827
// List to store global constants, such as strings used in many places.
2928
// constants are referred to their index in this list, starting at zero.
3029
repeated Constant constants = 4;
@@ -105,25 +104,6 @@ message Moment {
105104
reserved 3;
106105
}
107106

108-
// The quantum circuit, specified as a series of operations at specific
109-
// start times.
110-
message Schedule {
111-
// A list of all the operations and their absolute start times.
112-
repeated ScheduledOperation scheduled_operations = 3;
113-
}
114-
115-
// An operation occurring at a specific start time.
116-
message ScheduledOperation {
117-
// Which operation is to be scheduled.
118-
Operation operation = 1;
119-
120-
// The start time of the operation, with zero representing the absolute
121-
// start of the circuit.
122-
//
123-
// This must be consistent with the moment structure and must be positive.
124-
int64 start_time_picos = 2;
125-
}
126-
127107
// The language in which the program is expressed.
128108
message Language {
129109
// The name of the gate set being used.
@@ -223,9 +203,8 @@ message WaitGate {
223203

224204
// An operation acts on a set of qubits.
225205
message Operation {
226-
// Which gate this operation corresponds to.
227-
// Populated pre-v2.5+.
228-
Gate gate = 1 [deprecated = true];
206+
// Previously deprecated fields. Do not use.
207+
reserved 1, 2;
229208

230209
// Each gate should populate one possible gate message
231210
// depending on the type desired. Only populated in v2.5+.
@@ -248,17 +227,13 @@ message Operation {
248227
ResetGate resetgate = 24;
249228
}
250229

251-
// Map from the argument name to the Argument needed to fully specify
252-
// the gate. Only populated pre-v2.5+.
253-
map<string, Arg> args = 2 [deprecated = true];
254-
255230
// Which qubits the operation acts on.
256231
// Operations should populate one of the following two
257232
// fields: either to specify the qubit directly or
258233
// to reference an index in the enclosing Program's
259234
// constant messages. Note that qubit_constant_index
260235
// will only be populated in v2.5+
261-
repeated Qubit qubits = 3;
236+
repeated Qubit qubits = 3 [deprecated = true];
262237
repeated int32 qubit_constant_index = 6;
263238

264239
// Token that can be used to specify a version of a gate.

cirq-google/cirq_google/api/v2/program_pb2.py

Lines changed: 120 additions & 130 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cirq-google/cirq_google/api/v2/program_pb2.pyi

Lines changed: 5 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cirq-google/cirq_google/engine/engine_program_test.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,6 @@ def mock_grpc_client():
316316
yield _fixture
317317

318318

319-
@mock.patch('cirq_google.engine.engine_client.EngineClient.get_program_async')
320-
def test_get_circuit_v2_unknown_gateset(get_program_async):
321-
program = cg.EngineProgram('a', 'b', EngineContext())
322-
get_program_async.return_value = quantum.QuantumProgram(
323-
code=util.pack_any(
324-
v2.program_pb2.Program(language=v2.program_pb2.Language(gate_set="BAD_GATESET"))
325-
)
326-
)
327-
328-
with pytest.raises(ValueError, match='BAD_GATESET'):
329-
program.get_circuit()
330-
331-
332319
@mock.patch('cirq_google.engine.engine_client.EngineClient.get_program_async')
333320
def test_get_circuit_unsupported_program_type(get_program_async):
334321
program = cg.EngineProgram('a', 'b', EngineContext())

cirq-google/cirq_google/serialization/circuit_serializer.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ def deserialize(self, proto: v2.program_pb2.Program) -> cirq.Circuit:
391391
a schedule is attempted.
392392
NotImplementedError: If the program proto does not contain a circuit or schedule.
393393
"""
394-
if not proto.HasField('language') or not proto.language.gate_set:
395-
raise ValueError('Missing gate set specification.')
396-
if proto.language.gate_set != self.name:
397-
raise ValueError(
398-
f'Gate set in proto was {proto.language.gate_set} but expected {self.name}'
399-
)
400394
which = proto.WhichOneof('program')
401395

402396
if which == 'circuit':

cirq-google/cirq_google/serialization/circuit_serializer_test.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -680,18 +680,6 @@ def test_serialize_unrecognized():
680680
serializer.serialize("not quite right")
681681

682682

683-
def default_circuit_proto():
684-
op1 = v2.program_pb2.Operation()
685-
op1.gate.id = 'x_pow'
686-
op1.args['half_turns'].arg_value.string_value = 'k'
687-
op1.qubits.add().id = '1_1'
688-
689-
return v2.program_pb2.Circuit(
690-
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT,
691-
moments=[v2.program_pb2.Moment(operations=[op1])],
692-
)
693-
694-
695683
def default_circuit():
696684
return cirq.FrozenCircuit(
697685
cirq.X(cirq.GridQubit(1, 1)) ** sympy.Symbol('k'),
@@ -701,7 +689,7 @@ def default_circuit():
701689

702690
def test_serialize_circuit_op_errors():
703691
serializer = cg.CircuitSerializer()
704-
constants = [default_circuit_proto()]
692+
constants = [serializer.serialize(default_circuit()).circuit]
705693
raw_constants = {default_circuit(): 0}
706694

707695
op = cirq.CircuitOperation(default_circuit())
@@ -715,26 +703,6 @@ def test_serialize_circuit_op_errors():
715703
serializer._serialize_circuit_op(op, raw_constants=raw_constants)
716704

717705

718-
def test_deserialize_unsupported_gate_type():
719-
serializer = cg.CircuitSerializer()
720-
operation_proto = op_proto(
721-
{
722-
'gate': {'id': 'no_pow'},
723-
'args': {'half_turns': {'arg_value': {'float_value': 0.125}}},
724-
'qubits': [{'id': '1_1'}],
725-
}
726-
)
727-
proto = v2.program_pb2.Program(
728-
language=v2.program_pb2.Language(arg_function_language='', gate_set=_SERIALIZER_NAME),
729-
circuit=v2.program_pb2.Circuit(
730-
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT,
731-
moments=[v2.program_pb2.Moment(operations=[operation_proto])],
732-
),
733-
)
734-
with pytest.raises(ValueError, match='no_pow'):
735-
serializer.deserialize(proto)
736-
737-
738706
def test_serialize_op_unsupported_type():
739707
serializer = cg.CircuitSerializer()
740708
q0 = cirq.GridQubit(1, 1)
@@ -759,42 +727,6 @@ def with_qubits(self, *qubits):
759727
serializer.serialize(cirq.Circuit(null_op))
760728

761729

762-
def test_deserialize_invalid_gate_set():
763-
serializer = cg.CircuitSerializer()
764-
proto = v2.program_pb2.Program(
765-
language=v2.program_pb2.Language(gate_set='not_my_gate_set'),
766-
circuit=v2.program_pb2.Circuit(
767-
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT, moments=[]
768-
),
769-
)
770-
with pytest.raises(ValueError, match='not_my_gate_set'):
771-
serializer.deserialize(proto)
772-
773-
proto.language.gate_set = ''
774-
with pytest.raises(ValueError, match='Missing gate set'):
775-
serializer.deserialize(proto)
776-
777-
proto = v2.program_pb2.Program(
778-
circuit=v2.program_pb2.Circuit(
779-
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT, moments=[]
780-
)
781-
)
782-
with pytest.raises(ValueError, match='Missing gate set'):
783-
serializer.deserialize(proto)
784-
785-
786-
def test_deserialize_schedule_not_supported():
787-
serializer = cg.CircuitSerializer()
788-
proto = v2.program_pb2.Program(
789-
language=v2.program_pb2.Language(gate_set=_SERIALIZER_NAME),
790-
schedule=v2.program_pb2.Schedule(
791-
scheduled_operations=[v2.program_pb2.ScheduledOperation(start_time_picos=0)]
792-
),
793-
)
794-
with pytest.raises(ValueError, match='no longer supported'):
795-
serializer.deserialize(proto)
796-
797-
798730
def test_deserialize_fsim_missing_parameters():
799731
serializer = cg.CircuitSerializer()
800732
proto = circuit_proto(

0 commit comments

Comments
 (0)