Skip to content

Commit 97e8357

Browse files
dabaconrht
authored andcommitted
Add json serialization to sweeps (quantumlib#5618)
Adds missing json serialization for sweep objects.
1 parent 0693747 commit 97e8357

File tree

15 files changed

+119
-6
lines changed

15 files changed

+119
-6
lines changed

cirq-core/cirq/json_resolver_cache.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def _symmetricalqidpair(qids):
153153
'LineQubit': cirq.LineQubit,
154154
'LineQid': cirq.LineQid,
155155
'LineTopology': cirq.LineTopology,
156+
'Linspace': cirq.Linspace,
157+
'ListSweep': cirq.ListSweep,
156158
'MatrixGate': cirq.MatrixGate,
157159
'MixedUnitaryChannel': cirq.MixedUnitaryChannel,
158160
'MeasurementKey': cirq.MeasurementKey,
@@ -187,6 +189,8 @@ def _symmetricalqidpair(qids):
187189
'PhasedISwapPowGate': cirq.PhasedISwapPowGate,
188190
'PhasedXPowGate': cirq.PhasedXPowGate,
189191
'PhasedXZGate': cirq.PhasedXZGate,
192+
'Points': cirq.Points,
193+
'Product': cirq.Product,
190194
'ProductState': cirq.ProductState,
191195
'ProductOfSums': cirq.ProductOfSums,
192196
'ProjectorString': cirq.ProjectorString,
@@ -219,6 +223,7 @@ def _symmetricalqidpair(qids):
219223
'TwoQubitDiagonalGate': cirq.TwoQubitDiagonalGate,
220224
'TwoQubitGateTabulation': cirq.TwoQubitGateTabulation,
221225
'_UnconstrainedDevice': cirq.devices.unconstrained_device._UnconstrainedDevice,
226+
'_Unit': cirq.study.sweeps._Unit,
222227
'VarianceStoppingCriteria': cirq.work.VarianceStoppingCriteria,
223228
'VirtualTag': cirq.VirtualTag,
224229
'WaitGate': cirq.WaitGate,
@@ -233,6 +238,7 @@ def _symmetricalqidpair(qids):
233238
'YPowGate': cirq.YPowGate,
234239
'YYPowGate': cirq.YYPowGate,
235240
'_ZEigenState': cirq.value.product_state._ZEigenState, # type: ignore
241+
'Zip': cirq.Zip,
236242
'ZPowGate': cirq.ZPowGate,
237243
'ZZPowGate': cirq.ZZPowGate,
238244
# Old types, only supported for backwards-compatibility
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cirq_type": "Linspace",
3+
"key": "a",
4+
"start": 0,
5+
"stop": 1,
6+
"length": 4
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq.Linspace("a", start=0, stop=1, length=4)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"cirq_type": "ListSweep",
3+
"resolver_list": [
4+
{
5+
"cirq_type": "ParamResolver",
6+
"param_dict": [
7+
[
8+
"a",
9+
0.1
10+
]
11+
]
12+
},
13+
{
14+
"cirq_type": "ParamResolver",
15+
"param_dict": [
16+
[
17+
"b",
18+
0.2
19+
]
20+
]
21+
}
22+
]
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq.ListSweep([cirq.ParamResolver({'a': 0.1}), cirq.ParamResolver({'b': 0.2})])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cirq_type": "Points",
3+
"key": "a",
4+
"points": [
5+
0,
6+
0.4
7+
]
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq.Points('a', [0, 0.4])
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"cirq_type": "Product",
3+
"factors": [
4+
{
5+
"cirq_type": "Linspace",
6+
"key": "a",
7+
"start": 0,
8+
"stop": 1,
9+
"length": 2
10+
},
11+
{
12+
"cirq_type": "Linspace",
13+
"key": "b",
14+
"start": 0,
15+
"stop": 2,
16+
"length": 4
17+
}
18+
]
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq.Product(cirq.Linspace('a', start=0, stop=1, length=2), cirq.Linspace('b', start=0, stop=2, length=4))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"cirq_type": "Zip",
3+
"sweeps": [
4+
{
5+
"cirq_type": "Linspace",
6+
"key": "a",
7+
"start": 0,
8+
"stop": 1,
9+
"length": 2
10+
},
11+
{
12+
"cirq_type": "Linspace",
13+
"key": "b",
14+
"start": 0,
15+
"stop": 2,
16+
"length": 4
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)