-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Currently Cirq has a bit of a performance problem. One of the contributing factors to this is that there are very few "escape hatches" that you can use to opt out of features that slow things down. This suggestion is to add one such escape hatch.
A "flat sample" is a 2d numpy uint8 array where the major index is "repetition index" and the minor axis lists off the output bits ordered by moment, then by within-moment order, then by qubit order within each measurement operation. If we want to go even more extreme, the array could be bit packed to reduce space usage by 8x although then it's much harder for people to use.
To be explicit:
k = 0
for t, moment in enumerate(circuit):
for op in moment:
if isinstance(op.gate, cirq.MeasurementGate):
for q in op.qubits:
print(f"flat index {k} refers to the measurement of qubit {q} in moment {t}")
k += 1
Flat measurements can be more performant than non-flat measurements because they don't require scattering values across memory as they are collected. They also implicitly avoid key collision issues to do with measurements being repeated in a loop. This makes them much more amenable to e.g. error correction circuits.
I propose that we modify Sampler
to have a flat_sample(circuit)
method that by default delegates to Sampler.run
, but which we then write more efficient implementations for in cirq.Simulator.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status