quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
310 stars 90 forks source link

Sampling from a tableau? #708

Closed BrunoLiegiBastonLiegi closed 4 months ago

BrunoLiegiBastonLiegi commented 4 months ago

Is there any way to directly generate the samples starting from a tableau and not a circuit? I understand that the standard way is to compile the sampler starting from the circuit

import stim
c = stim.Circuit('''
   X 2
   M 0 1 2
''')
s = c.compile_sampler()
s.sample(shots=1)

but I was wondering whether the CompiledMeasurementSampler it produces could be directly initialized from a tableu, and maybe the qubits one wants to measure.

Strilanc commented 4 months ago

What exactly would it be sampling? The state with the stabilizers of the tableau? I think this is well covered by something like

c = tableau.to_circuit("graph_state")
c.append("M", range(c.num_qubits))
s = c.compiler_sampler()
BrunoLiegiBastonLiegi commented 4 months ago

What exactly would it be sampling? The state with the stabilizers of the tableau? I think this is well covered by something like

c = tableau.to_circuit("graph_state")
c.append("M", range(c.num_qubits))
s = c.compiler_sampler()

Ah I see, indeed, you can always convert to a circuit and sample measurements from there. Yep I think this works for what I need, thanks!