-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathprogram.proto
More file actions
732 lines (614 loc) · 21.6 KB
/
program.proto
File metadata and controls
732 lines (614 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
syntax = "proto3";
package cirq.google.api.v2;
import "tunits/proto/tunits.proto";
import "cirq_google/api/v2/ndarrays.proto";
option java_package = "com.google.cirq.google.api.v2";
option java_outer_classname = "ProgramProto";
option java_multiple_files = true;
// A quantum program.
message Program {
// The language in which the program is written.
Language language = 1 [deprecated = true];
// Programs can be specified by a circuit or a schedule.
oneof program {
// A circuit is an abstract representation as a series of moments, each
// 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;
}
// 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;
}
// Constants, such as long strings, that are used throughout the circuit.
// These constants can be stored here to save space.
message Constant {
oneof const_value {
// String value used throughout the circuit, such as for token values
string string_value = 1;
// Sub Circuit used for CircuitOperations
Circuit circuit_value = 2;
// Qubits used within the circuit (only populated in v2.5+)
Qubit qubit = 3;
// Moments used multiple times in a circuit
Moment moment_value = 4;
// Operations used multiple times in a circuit
Operation operation_value = 5;
// Tags used multiple times in a circuit
Tag tag_value = 6;
}
}
// The quantum circuit, specified as a series of moments (abstract
// slices of times with gates acting on disjoint sets of qubits).
message Circuit {
// How the circuit is scheduled.
enum SchedulingStrategy {
// The scheduling strategy is unspecified.
SCHEDULING_STRATEGY_UNSPECIFIED = 0;
// Each operation in a moment starts at the same time. The start of the
// next moment is given by the duration of the longest operation in
// the current moment.
MOMENT_BY_MOMENT = 1;
}
SchedulingStrategy scheduling_strategy = 1;
// The moments of the circuit, with the first element corresponding to the
// first set of operations to apply, etc.
repeated Moment moments = 2;
// The index of the moment in the top-level constant table.
// In order to preserve ordering, either this field should be populated
// or the moments field, but not both.
// This field is used to reduce size of circuits that contain many
// repeated moments.
repeated int32 moment_indices = 3;
// Deprecated field, do not use.
reserved 4;
// Indices in the constant table for tags associated with the circuit
repeated int32 tag_indices = 5;
}
// A moment is a collection of operations and circuit operations that operate
// on a disjoint set of qubits. Conceptually, a moment represents operations
// that all occur in the same finite period of time.
message Moment {
// All of the gate operations in the moment. Each operation and circuit
// operation must act on different qubits.
repeated Operation operations = 1;
// All of the circuit operations in the moment. Each operation and circuit
// operation must act on different qubits.
repeated CircuitOperation circuit_operations = 2;
// All of the operations in the moment that are stored in the constants
// table. Each operation should be stored in either `operations`
// or `operation_indices`. Putting operations into the symbol
// table should be preferred for circuits with repeated operations
// for improved serialization size.
repeated int32 operation_indices = 4;
// Deprecated field id, do not use.
reserved 3;
// Indices in the constant table for tags associated with the circuit
repeated int32 tag_indices = 5;
}
// The language in which the program is expressed.
message Language {
// The name of the gate set being used.
//
// Valid names for the gate sets can be found in
// cirq_google/serialization/gate_sets.py.
//
// Deprecated: A device now only supports a single gate set.
// Previously, the value of this field also refers to the name of the
// serializer for the program. Currently, the only serializer available is
// CircuitSerializer in cirq_google/serialization/circuit_serializer.py.
string gate_set = 1 [deprecated = true];
// The language supported by ArgFunctions. These specifies what allowed
// ArgFunction types there are.
//
// Valid names for the arg function language can be found in
// cirq/google/arg_func_langs.py
string arg_function_language = 2 [deprecated = true];
}
// Argument that is constrained to a float or symbolic expression
message FloatArg {
oneof arg {
float float_value = 1;
string symbol = 2;
ArgFunction func = 3;
}
}
// Representation of cirq.XPowGate
message XPowGate {
FloatArg exponent = 1;
}
// Representation of cirq.YPowGate
message YPowGate {
FloatArg exponent = 1;
}
// Representation of cirq.ZPowGate
message ZPowGate {
FloatArg exponent = 1;
// If true, this is equivalent to:
// cirq.ZPowGate(...).with_tags(cirq.google.PhysicalZTag)
bool is_physical_z = 2;
}
// Representation of cirq.PhasedXPowGate
message PhasedXPowGate {
FloatArg phase_exponent = 1;
FloatArg exponent = 2;
}
// Representation of cirq.PhasedXZGate
message PhasedXZGate {
FloatArg x_exponent = 1;
FloatArg z_exponent = 2;
FloatArg axis_phase_exponent = 3;
}
// Representation of cirq.CZPowGate
message CZPowGate {
FloatArg exponent = 1;
}
// Representation of cirq.FSimGate
message FSimGate {
FloatArg theta = 1;
FloatArg phi = 2;
// If true, this is equivalent to:
// cirq.FSimGate(...).with_tags(cirq_google.FSimViaModelTag()).
// This field controls how we translate the gate implementation.
bool translate_via_model = 3;
}
// Representation of cirq.ISwapPowGate
message ISwapPowGate {
FloatArg exponent = 1;
}
// Representation of an iswap-like gate
// with theta=pi/2 and a non-zero hardware-dependent phi angle
message ISwapLikeGate {
// Original gate, for deserializing faithfully.
enum OriginalCirqGate {
UNSPECIFIED = 0;
SYCAMORE = 1;
WILLOW = 2;
}
OriginalCirqGate original_gate = 1;
}
// Representation of cirq.MeasurementGate
// i.e. cirq.measure
message MeasurementGate {
Arg key = 1;
Arg invert_mask = 2;
}
// Representation of cirq.WaitGate
message WaitGate {
// Duration of the waiting period,
// serialized to the number of nanoseconds
FloatArg duration_nanos = 1;
}
// Representation of cirq.DepolarizingChannel
message DepolarizingChannel {
FloatArg probability = 1;
int32 num_qubits = 2;
}
// Representation of cirq.RandomGateChannel
message RandomGateChannel {
FloatArg probability = 1;
Operation sub_gate = 2;
}
// Representation of noisy channels
// These should only be used for serialization
// of noisy circuits for simulation.
// These channels would generally not be supported
// by hardware.
message NoiseChannel {
oneof channel_value {
DepolarizingChannel depolarizingchannel = 1;
RandomGateChannel randomgatechannel = 2;
}
}
// An operation acts on a set of qubits.
// next available id = 28
message Operation {
// 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+.
oneof gate_value {
XPowGate xpowgate = 7;
YPowGate ypowgate = 8;
ZPowGate zpowgate = 9;
PhasedXPowGate phasedxpowgate = 10;
PhasedXZGate phasedxzgate = 11;
CZPowGate czpowgate = 12;
FSimGate fsimgate = 13;
ISwapPowGate iswappowgate = 14;
MeasurementGate measurementgate = 15;
WaitGate waitgate = 16;
InternalGate internalgate = 17;
CouplerPulseGate couplerpulsegate = 18;
IdentityGate identitygate = 19;
HPowGate hpowgate = 20;
SingleQubitCliffordGate singlequbitcliffordgate = 21;
ResetGate resetgate = 24;
ISwapLikeGate iswaplikegate = 26;
NoiseChannel noisechannel = 27;
}
// 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 [deprecated = true];
repeated int32 qubit_constant_index = 6;
// Token that can be used to specify a version of a gate.
// For instance, a gate that has been calibrated for a circuit.
//
// The token can be specified as a string or as a reference to
// the constant table of the circuit.
oneof token {
string token_value = 4 [deprecated = true];
int32 token_constant_index = 5 [deprecated = true];
}
// To be deprecated
repeated Tag tags = 22;
// Indices in the constant table for tags associated with the operation
repeated int32 tag_indices = 23;
// Classical conditions
// Note that this condition is not a sympy expression
// as it has a relation such as "==", "<" etc
repeated Arg conditioned_on = 25;
}
message DynamicalDecouplingTag {
optional string protocol = 1;
}
// Messages for tags that can modify operations
// These are often directives to hardware specifying
// how the operation should be executed.
message Tag {
oneof tag {
// Tag to denote a composite dynamical decoupling operation.
// Should generally be applied to cirq.I gates.
DynamicalDecouplingTag dynamical_decoupling = 1;
// Directs the hardware to ignore moment-based
// synchronization and to instead schedule
// operations as soon as possible for these qubits.
NoSyncTag no_sync = 2;
// Operation should do phase matching to match phase
// required for subsequent operations
PhaseMatchTag phase_match = 3;
// Only applicable to Z gates and other gates
// that have Z gates as part of their internal operation
// This indicates that the Z gates could be executed on
// hardware rather than be computed virtually as part
// of phase matching.
PhysicalZTag physical_z = 4;
// Indicates that the operations are classical states
ClassicalStateTag classical_state = 5;
// Field id 6 Reserved for OverlayTag, will add in a subsequent PR.
// Uses parameter model to interpolate FSim gate.
FSimViaModelTag fsim_via_model = 7;
// Calibration Tag
CalibrationTag calibration_tag = 9;
// Catch-all for all gates that do not fit into the
// above tags.
InternalTag internal_tag = 8;
}
}
// Tag for operations that should do phase matching to match phase
// required for subsequent operations
message PhaseMatchTag {}
message PhysicalZTag {}
// Tag to indicate that a state prep circuit produces a classical state.
// This serves as a hint to the compiler that we can ignore virtual Z phases
message ClassicalStateTag {}
message FSimViaModelTag {}
// Tag to remove moment-based synchronization
// The reverse and forward arguments control the
// number of moments to reverse synchronization.
message NoSyncTag {
oneof rev {
// Number of synchronizations before the operation to remove
int32 reverse = 1;
// Remove all possible synchronizations
bool remove_all_syncs_before = 2;
}
oneof fwd {
// Number of synchronizations after the operation to remove
int32 forward = 3;
// Remove all possible synchronizations
bool remove_all_syncs_after = 4;
}
}
// Tag to specify specific override tokens for operations or circuits.
message CalibrationTag {
// Token to serialize
string token = 1;
}
// Tag to represent any internal tags or tags not yet
// implemented in the proto.
message InternalTag {
// Name of the tag
string tag_name = 1;
// Python package of the Tag
string tag_package = 2;
// Instantiation arguments of the Tag
map<string, Arg> tag_args = 3;
map<string, CustomArg> custom_args = 4;
}
// The instruction identifying the action taken on the quantum computer.
message Gate {
// Name for the Gate.
//
// These names must match those specified in the gate set. This is found
// in cirq/google/gate_sets.py.
string id = 1;
}
// An identifier for a qubit.
message Qubit {
// Id of the qubit. These depend on the device being scheduled upon.
//
// Typically ids for qubits on a line are simple string versions of integers,
// while for qubits on a square grid these are integers separated by a
// underscore, i.e. '0_1', '1_2', etc.
string id = 2;
}
// Arguments needed to specify a gate.
message Arg {
// Arguments are either a number, a symbol, or an argument function
// (which recursively depends on Arg).
//
// ArgValue is used to specify an argument that does not vary
// depending on RunContext.
//
// Symbol is used when an argument will be resolved (supplied a value)
// by a Run Context.
//
// Functions are used to define a simple s-expression tree describing
// how to combine numbers and symbols mathematically.
//
// The argument can also be specified as a lookup in the Constant
// table of the Circuit.
oneof arg {
ArgValue arg_value = 1;
string symbol = 2;
ArgFunction func = 3;
int32 constant_index = 4;
MeasurementKey measurement_key = 5;
}
}
// Value that can be passed as an argument to a gate.
message ArgValue {
oneof arg_value {
float float_value = 1;
RepeatedBoolean bool_values = 2;
string string_value = 3;
double double_value = 4;
RepeatedInt64 int64_values = 5;
RepeatedDouble double_values = 6;
RepeatedString string_values = 7;
tunits.Value value_with_unit = 8;
bool bool_value = 9;
bytes bytes_value = 10;
Complex complex_value = 11;
Tuple tuple_value = 12;
NDArray ndarray_value = 13;
}
}
// A repeated int value.
message RepeatedInt64 {
repeated int64 values = 1;
}
// A repeated double value.
message RepeatedDouble {
repeated double values = 1;
}
// A repeated string value.
message RepeatedString {
repeated string values = 1;
}
// A repeated boolean value.
message RepeatedBoolean {
repeated bool values = 1;
}
// Representation of a mixed tuple of values
message Tuple {
// Original (python) type of the data
enum SequenceType {
UNSPECIFIED = 0;
LIST = 1;
TUPLE = 2;
SET = 3;
FROZENSET = 4;
}
SequenceType sequence_type = 1;
repeated Arg values = 2;
}
// Representation of a complex number
message Complex {
double real_value = 1;
double imag_value = 2;
}
message NDArray {
oneof arr {
Complex128Array complex128_array = 1;
Complex64Array complex64_array = 2;
Float16Array float16_array = 3;
Float32Array float32_array = 4;
Float64Array float64_array = 5;
Int64Array int64_array = 6;
Int32Array int32_array = 7;
Int16Array int16_array = 8;
Int8Array int8_array = 9;
UInt8Array uint8_array = 10;
BitArray bit_array = 11;
}
}
// A function of arguments. This is an s-expression tree representing
// mathematically the function being evaluated.
//
// What language is supported is specified by the arg_function_language
// in the language message.
message ArgFunction {
// The name of the function. I.e. if the function is the sum of two symbols,
// this could be '+', and the args would be two string symbol values.
//
// Valid values for the type are given in cirq/google/arg_func_langs.py
// and must be consistent with the arg_function_language specified in the
// language field of the program.
string type = 1;
// The arguments to the function.
repeated Arg args = 2;
}
// An operation that applies a modified version of a reference circuit. The
// circuit is stored in the top-level Constants table; the mappings in this
// object specify how that circuit should be modified for this operation.
//
// Multiple CircuitOperations may reference the same base circuit even if their
// mappings of that circuit are different.
message CircuitOperation {
// The index of the circuit in the top-level constant table.
int32 circuit_constant_index = 1;
// Specifier for repetitions of the circuit, which contains either a number
// of repetitions or a list of repetition IDs.
RepetitionSpecification repetition_specification = 2;
// Map from qubits in the "inner" circuit (referenced by
// circuit_constant_index) to qubits in the "outer" circuit (the one that
// contains this operation).
QubitMapping qubit_map = 3;
// Map of measurement keys in the "inner" circuit (referenced by
// circuit_constant_index) to measurement keys in the "outer" circuit (the
// one that contains this operation).
MeasurementKeyMapping measurement_key_map = 4;
// Map of args in the "inner" circuit (referenced by circuit_constant_index)
// to args in the "outer" circuit (the one that contains this operation).
ArgMapping arg_map = 5;
// Classical conditions
// Condition for repeating the circuit until this condition is true.
optional Arg repeat_until = 6;
// Condition for executing the circuit operation only if this condition is true.
repeated Arg conditioned_on = 7;
bool use_repetition_ids = 8;
}
// A description of the repetitions of a subcircuit. IDs are used as suffixes
// for measurements in the repeated subcircuit; if repetition_count is given
// instead, the IDs will simply be the integers [0..N-1].
message RepetitionSpecification {
// An ordered list of IDs for a sequence of repetitions.
message RepetitionIds {
repeated string ids = 1;
}
oneof repetition_value {
// A list of unique IDs, one per repetition of the subcircuit.
RepetitionIds repetition_ids = 1;
// An integer number of repetitions to perform.
int32 repetition_count = 2;
}
}
// A mapping of qubits from one value to another. All mappings are applied
// simultaneously and independently; for example, [(a, b), (b, a)] will swap
// qubits a and b.
message QubitMapping {
// Indicates that qubit "key" should be replaced with "value".
message QubitEntry {
Qubit key = 1;
Qubit value = 2;
}
// A list of qubit mappings to apply.
repeated QubitEntry entries = 1;
}
// A key for matching a measurement event to its results.
message MeasurementKey {
string string_key = 1;
// Used in conditional statements representing the path to the key
// in a multi-level circuit (with repeated or nested circuits).
// See cirq.MeasurementKey for more details.
repeated string path = 2;
// Used in classical conditions to specify which measurement
// should be used if the measurement is repeated.
// Specified as a negative number meaning how many measurements ago.
// If not specified, default is -1, meaning the last measured value.
optional int32 index = 3;
}
// A mapping of measurement keys from one value to another. All mappings are
// applied simultaneously and independently; for example, [(a, b), (b, a)] will
// swap measurement keys a and b.
message MeasurementKeyMapping {
// Indicates that measurement key "key" should be replaced with "value".
message MeasurementKeyEntry {
MeasurementKey key = 1;
MeasurementKey value = 2;
}
// A list of measurement key mappings to apply.
repeated MeasurementKeyEntry entries = 1;
}
// A mapping of args from one value to another. All mappings are applied
// simultaneously and independently; for example, [(a, b), (b, a)] will swap
// args a and b.
message ArgMapping {
// Indicates that arg "key" should be replaced with "value".
message ArgEntry {
Arg key = 1;
Arg value = 2;
}
// A list of arg mappings to apply.
repeated ArgEntry entries = 1;
}
message FunctionInterpolation {
// The x_values must be sorted in ascending order.
// The x_values and y_values must be of the same length.
repeated float x_values = 1 [packed = true]; // The independent variable.
repeated float y_values = 2 [packed = true]; // The dependent variable.
// Currently only piecewise linear interpolation (i.e. np.interp) is
// supported. That's we connect (x[i], y[i]) to (x[i+1], y[i+1]))
}
message CustomArg {
oneof custom_arg {
FunctionInterpolation function_interpolation_data = 1;
}
}
message InternalGate {
string name = 1; // Gate name.
string module = 2; // Gate module.
int32 num_qubits = 3; // Number of qubits. Required during deserialization.
map<string, Arg> gate_args = 4; // Gate args.
// Custom args are arguments that require special processing during
// deserialization. The `key` is the argument in the internal class's
// constructor, the `value` is a representation from which an internal object
// can be constructed.
map<string, CustomArg> custom_args = 5;
}
message CouplerPulseGate {
optional FloatArg hold_time_ps = 1; // ps=picoseconds.
optional FloatArg rise_time_ps = 2; // ps=picoseconds.
optional FloatArg padding_time_ps = 3; // ps=picoseconds.
optional FloatArg coupling_mhz = 4;
optional FloatArg q0_detune_mhz = 5;
optional FloatArg q1_detune_mhz = 6;
}
message CliffordTableau {
// Number of qubits the CliffordTableau acts on.
optional int32 num_qubits = 1;
// The initial state.
optional int32 initial_state = 2;
// A flattened version of the `rs` array.
repeated bool rs = 3;
// A flattened version of the `xs` array.
repeated bool xs = 4;
// A flattened version of the `zs` array.
repeated bool zs = 5;
}
message SingleQubitCliffordGate {
CliffordTableau tableau = 1;
}
message IdentityGate {
repeated uint32 qid_shape = 1;
}
message HPowGate {
FloatArg exponent = 1;
}
message ResetGate {
// Type of reset to be executed (hardware dependent)
// Internal users should use the name of the class.
// (Note that this is not used for public-facing circuits,
// which will default to cirq.ResetChannel)
string reset_type = 1;
// Additional arguments that can be sent to the reset implementation.
map<string, Arg> arguments = 2;
}