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
37 changes: 6 additions & 31 deletions cirq-google/cirq_google/api/v2/program.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ message Program {
// moment having a set of gates that act on disjoint qubits. Circuits don't
// have absolute times for their operations (gates acting on qubits).
Circuit circuit = 2;

// Schedules are a list of operations (gates acting on qubits) that specify
// absolute start times for the operations.
Schedule schedule = 3;
}

// Previously deprecated field. Do not use.
reserved 3;

// List to store global constants, such as strings used in many places.
// constants are referred to their index in this list, starting at zero.
repeated Constant constants = 4;
Expand Down Expand Up @@ -105,25 +104,6 @@ message Moment {
reserved 3;
}

// The quantum circuit, specified as a series of operations at specific
// start times.
message Schedule {
// A list of all the operations and their absolute start times.
repeated ScheduledOperation scheduled_operations = 3;
}

// An operation occurring at a specific start time.
message ScheduledOperation {
// Which operation is to be scheduled.
Operation operation = 1;

// The start time of the operation, with zero representing the absolute
// start of the circuit.
//
// This must be consistent with the moment structure and must be positive.
int64 start_time_picos = 2;
}

// The language in which the program is expressed.
message Language {
// The name of the gate set being used.
Expand Down Expand Up @@ -223,9 +203,8 @@ message WaitGate {

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

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

// Map from the argument name to the Argument needed to fully specify
// the gate. Only populated pre-v2.5+.
map<string, Arg> args = 2 [deprecated = true];

// Which qubits the operation acts on.
// Operations should populate one of the following two
// fields: either to specify the qubit directly or
// to reference an index in the enclosing Program's
// constant messages. Note that qubit_constant_index
// will only be populated in v2.5+
repeated Qubit qubits = 3;
repeated Qubit qubits = 3 [deprecated=true];
repeated int32 qubit_constant_index = 6;

// Token that can be used to specify a version of a gate.
Expand Down
250 changes: 120 additions & 130 deletions cirq-google/cirq_google/api/v2/program_pb2.py

Large diffs are not rendered by default.

103 changes: 5 additions & 98 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.

13 changes: 0 additions & 13 deletions cirq-google/cirq_google/engine/engine_program_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,6 @@ def mock_grpc_client():
yield _fixture


@mock.patch('cirq_google.engine.engine_client.EngineClient.get_program_async')
def test_get_circuit_v2_unknown_gateset(get_program_async):
program = cg.EngineProgram('a', 'b', EngineContext())
get_program_async.return_value = quantum.QuantumProgram(
code=util.pack_any(
v2.program_pb2.Program(language=v2.program_pb2.Language(gate_set="BAD_GATESET"))
)
)

with pytest.raises(ValueError, match='BAD_GATESET'):
program.get_circuit()


@mock.patch('cirq_google.engine.engine_client.EngineClient.get_program_async')
def test_get_circuit_unsupported_program_type(get_program_async):
program = cg.EngineProgram('a', 'b', EngineContext())
Expand Down
6 changes: 0 additions & 6 deletions cirq-google/cirq_google/serialization/circuit_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,6 @@ def deserialize(self, proto: v2.program_pb2.Program) -> cirq.Circuit:
a schedule is attempted.
NotImplementedError: If the program proto does not contain a circuit or schedule.
"""
if not proto.HasField('language') or not proto.language.gate_set:
raise ValueError('Missing gate set specification.')
if proto.language.gate_set != self.name:
raise ValueError(
f'Gate set in proto was {proto.language.gate_set} but expected {self.name}'
)
which = proto.WhichOneof('program')

if which == 'circuit':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,6 @@ def test_serialize_unrecognized():
serializer.serialize("not quite right")


def default_circuit_proto():
op1 = v2.program_pb2.Operation()
op1.gate.id = 'x_pow'
op1.args['half_turns'].arg_value.string_value = 'k'
op1.qubits.add().id = '1_1'

return v2.program_pb2.Circuit(
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT,
moments=[v2.program_pb2.Moment(operations=[op1])],
)


def default_circuit():
return cirq.FrozenCircuit(
cirq.X(cirq.GridQubit(1, 1)) ** sympy.Symbol('k'),
Expand All @@ -696,7 +684,7 @@ def default_circuit():

def test_serialize_circuit_op_errors():
serializer = cg.CircuitSerializer()
constants = [default_circuit_proto()]
constants = [serializer.serialize(default_circuit()).circuit]
raw_constants = {default_circuit(): 0}

op = cirq.CircuitOperation(default_circuit())
Expand All @@ -710,26 +698,6 @@ def test_serialize_circuit_op_errors():
serializer._serialize_circuit_op(op, raw_constants=raw_constants)


def test_deserialize_unsupported_gate_type():
serializer = cg.CircuitSerializer()
operation_proto = op_proto(
{
'gate': {'id': 'no_pow'},
'args': {'half_turns': {'arg_value': {'float_value': 0.125}}},
'qubits': [{'id': '1_1'}],
}
)
proto = v2.program_pb2.Program(
language=v2.program_pb2.Language(arg_function_language='', gate_set=_SERIALIZER_NAME),
circuit=v2.program_pb2.Circuit(
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT,
moments=[v2.program_pb2.Moment(operations=[operation_proto])],
),
)
with pytest.raises(ValueError, match='no_pow'):
serializer.deserialize(proto)


def test_serialize_op_unsupported_type():
serializer = cg.CircuitSerializer()
q0 = cirq.GridQubit(1, 1)
Expand All @@ -754,42 +722,6 @@ def with_qubits(self, *qubits):
serializer.serialize(cirq.Circuit(null_op))


def test_deserialize_invalid_gate_set():
serializer = cg.CircuitSerializer()
proto = v2.program_pb2.Program(
language=v2.program_pb2.Language(gate_set='not_my_gate_set'),
circuit=v2.program_pb2.Circuit(
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT, moments=[]
),
)
with pytest.raises(ValueError, match='not_my_gate_set'):
serializer.deserialize(proto)

proto.language.gate_set = ''
with pytest.raises(ValueError, match='Missing gate set'):
serializer.deserialize(proto)

proto = v2.program_pb2.Program(
circuit=v2.program_pb2.Circuit(
scheduling_strategy=v2.program_pb2.Circuit.MOMENT_BY_MOMENT, moments=[]
)
)
with pytest.raises(ValueError, match='Missing gate set'):
serializer.deserialize(proto)


def test_deserialize_schedule_not_supported():
serializer = cg.CircuitSerializer()
proto = v2.program_pb2.Program(
language=v2.program_pb2.Language(gate_set=_SERIALIZER_NAME),
schedule=v2.program_pb2.Schedule(
scheduled_operations=[v2.program_pb2.ScheduledOperation(start_time_picos=0)]
),
)
with pytest.raises(ValueError, match='no longer supported'):
serializer.deserialize(proto)


def test_deserialize_fsim_missing_parameters():
serializer = cg.CircuitSerializer()
proto = circuit_proto(
Expand Down
Loading