1
$\begingroup$

Let's say one implements the following circuit in stim from the stim tutorial:

import stim  

def rep_code(distance,rounds,noise):
    circuit=stim.Circuit()
    qubits=range(2*distance+1)      
    data=qubits[::2]      
    measure=qubits[1::2]      
    pairs1=qubits[:-1]      
    circuit.append_operation("DEPOLARIZE1",data,noise)     
    circuit.append_operation("CNOT",pairs1)      
    pairs2=qubits[1:][::-1]      
    circuit.append_operation("CNOT",pairs2)      
    circuit.append_operation("MR",measure)      
    return circuit*rounds

circuit.compile_sampler().sample(1)[0] outputs the measurement outcomes. How does one output the Pauli error on the data qubits at the end of the circuit?

$\endgroup$

1 Answer 1

1
$\begingroup$

There is no option to sample the final Pauli frame exposed to stim's python API (as of 1.18). The closest you can get is to add measurement operations at the end of the circuit, which will be flipped if the Pauli frame anticommutes with the measurement basis.

You could alternatively consider using stim.TableauSimulator, which doesn't have a pauli frame but does give you magical access to the underlying state. For example, you can use stim.TableauSimulator.peek_observable_expectation.

In the underlying C++ API what you want is possible, via directly working with stim::FrameSimulator:

#include "stim.h"

void sample_final_frame(const stim::Circuit &circuit) {
    size_t shots = 256;
    size_t max_lookback = 1000000;
    auto rng = stim::externally_seeded_rng();
    stim::FrameSimulator frame_sim(
        circuit.count_qubits(),
        shots,
        max_lookback,
        rng);
    frame_sim.reset_all_and_run(circuit);

    // X errors now at frame_sim.x_table[qubit_index][shot_index]
    // Z errors now at frame_sim.z_table[qubit_index][shot_index]
    // Y = X*Z
    ...
}

One thing that might complicate whatever you were planning to use the frame for, is that Stim always partially randomizes the Pauli frame when collapsing operations are performed. For example, applying an R operation doesn't clear the Pauli frame. Instead, it randomly sets the frame to I or Z. This is how the Heisenberg uncertainty relationship between anticommuting observables is enforced by the frame simulator. The Pauli frame isn't just affected by errors, it's also affected by these sorts of anticommutation effects.

$\endgroup$
2
  • $\begingroup$ Thanks. I might use that then. My goal was to use stim to just create the circuit and then use the full error information i.e. the Pauli error on data qubits and measurement errors at the end of the circuit as an input to my own protocols. $\endgroup$
    – user111
    Commented Mar 23, 2022 at 5:15
  • $\begingroup$ I just see your edit. My circuit is just a stabilizer measurement circuit i.e. a bunch of CNOT gates (from data qubits to ancillary) followed by the measurement of the ancillary in an appropriate basis. $\endgroup$
    – user111
    Commented Mar 23, 2022 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.