Saving Objects to Disk

True-Qᵀᴹ objects can be saved to disk using the trueq.utils.save() function. They are saved in the Python pickle serial binary format and then compressed. After these objects have been saved to disk, they can be reloaded into Python with the global trueq.utils.load() function. The saved file persists beyond the call to load() and can be reused.

import os
import trueq as tq

# Make SRB CircuitCollection on qubit [1].
circuits = tq.make_srb([1], [4, 32, 64])

# Create a simulation object and fill the results of measurements into the circuits
# this is where you would fill in the results from running the experiment.
tq.Simulator().add_overrotation(0.05).run(circuits, n_shots=1024)

# Save to file with tq.utils.save().
filename = tq.utils.temporary_file_name() + ".bin"
print("Saving circuits to {} ...".format(filename))
tq.utils.save(circuits, filename)

# Load from file into new instance, and then analyze/print.
circuits_new = tq.load(filename)
print("\nSummary from saved/loaded file:\n")
circuits_new.fit().summarize()

Note

The file extension is irrelevant.

The CircuitCollection has its own save() method for convenience, which calls trueq.utils.save().


print("Saving circuits to {} ...".format(filename))
circuits.save(filename)

# Load from file into new instance, and then analyze/print.
circuits_new = tq.load(filename)
print("\nSummary from saved/loaded file:\n")
circuits_new.fit().summarize()