2
$\begingroup$

I'm trying to save and load large circuits from files in Stim. For example, if I use a generated surface code from the intro notebook

import stim

circuit = stim.Circuit.generated(
    "surface_code:unrotated_memory_z",
    rounds=100,
    distance=3,
    after_clifford_depolarization=0.001,
    after_reset_flip_probability=0.001,
    before_measure_flip_probability=0.001,
    before_round_data_depolarization=0.001
)

The way I would currently save this is with

with open('saved_circuit.stim', 'w') as f:
    f.write(circuit.__str__())

And then read it with

circuit_file = open('saved_circuit.stim', 'r')
circuit_text = circuit_file.read()
circuit_file.close()

circuit = stim.Circuit()
circuit.append_from_stim_program_text(circuit_text)

This works fine and all, but I got the feeling that because they went through the trouble of defining the stim circuit file format (.stim), it seemed that there would be simple methods like circuit.save('filename.stim') or circuit.load('filename.stim'). But I'm not having any luck finding any methods of the like. Right now my only solution is to define functions that do this, which is not a challenge, but just wondering if it's already an option.

$\endgroup$

1 Answer 1

1
$\begingroup$

In stim v1.9+ there's stim.Circuit.to_file, stim.Circuit.from_file, stim.DetectorErrorModel.to_file, stim.DetectorErrorModel.from_file.


As of stim v1.8 there aren't methods that take a path to read/write a circuit from.

The __str__ method is guaranteed to produce the file format specified in that document, and the constructor is guaranteed to parse its argument as that format.

$\endgroup$
1
  • $\begingroup$ I suppose at some moment of finding time, I could do a merge request with these methods, since it seems trivial to implement as a simple wrapper. Might turn out to be a more delicate issue! Thanks for the response $\endgroup$
    – Bebotron
    Jun 15, 2022 at 18:27

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.