Skip to content

Commit 913e68b

Browse files
authored
Add methods to serialize multi-programs in cirq_google (#7678)
- Adds a new Message in the Program proto for KeyedCircuit which can store multiple circuits indexed by parameters. - This also adds a pair of functions in CircuitSerializer called serialize_multi_program and deserialize_multi_program. - These can serialize a list of circuits, a map of circuits with string keys, or a function that returns a circuit (with a corresponding sweep object that specifies how to call the function).
1 parent 3317377 commit 913e68b

File tree

5 files changed

+552
-211
lines changed

5 files changed

+552
-211
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ message Program {
2828
// List to store global constants, such as strings used in many places.
2929
// constants are referred to their index in this list, starting at zero.
3030
repeated Constant constants = 4;
31+
32+
// A batch of circuits organized by a set of parameters. These
33+
// parameters should also be specified in the sweep as well.
34+
// This field can be used for efficient packing of circuit functions
35+
// that change based on parameters, or for batch sending of circuits.
36+
repeated KeyedCircuit keyed_circuits = 5;
3137
}
3238

3339
// Constants, such as long strings, that are used throughout the circuit.
@@ -54,6 +60,29 @@ message Constant {
5460
}
5561
}
5662

63+
64+
// A batch of circuits organized by a set of parameters. These
65+
// parameters should also be specified in the sweep as well.
66+
// This field can be used for efficient packing of circuit functions
67+
// that change based on parameters, or for batch sending of circuits.
68+
message KeyedCircuit {
69+
70+
// Arguments for a cirq circuit which comes from run_context.
71+
// The key will be the name of the argument, and the value
72+
// will be the value passed into the function.
73+
// e.g. Arguments for a circuit function such as:
74+
// def circuit_fn(freq_GHz: float, num_cycles: int) -> Circuit
75+
// would have the two entries: "freq_GHz" and "num_cycles"
76+
map<string, Arg> args = 1;
77+
78+
// The cirq circuit corresponding to the arguments args.
79+
Circuit circuit = 2;
80+
81+
// Optional key for program.
82+
// If provided, will be used as a key in a Mapping from string to Circuit.
83+
string key = 3;
84+
}
85+
5786
// The quantum circuit, specified as a series of moments (abstract
5887
// slices of times with gates acting on disjoint sets of qubits).
5988
message Circuit {

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

Lines changed: 152 additions & 146 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: 72 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)