Simulation
- class panqec.simulation.BaseSimulation(code: StabilizerCode, error_model: BaseErrorModel, compress: bool = True, verbose=True, rng=None)
Quantum Error Correction Simulation.
- __init__(code: StabilizerCode, error_model: BaseErrorModel, compress: bool = True, verbose=True, rng=None)
- load_results(output_file: str)
Load previously written results from directory.
- save_results(output_file: str)
Save results to directory.
- class panqec.simulation.BatchSimulation(output_file: str, label='unlabelled', on_update: ~typing.Callable = <function identity>, update_frequency: int = 5, save_frequency: int = 1, method: str = 'direct', log_file: str | None = None, verbose: bool = True)
Holds and controls many simulations.
- Parameters:
label (str) – The label of the files.
output_file (str) – Path to the file (.json or .json.gz) that will store the simulation results
label – Label of the batch simulation
on_update (Callable) – Function that gets called on every update.
update_frequency (int) – Frequency at which to update results.
save_frequency (int) – Frequency at which to write results to file on disk.
method (str) – The method can be either “direct” or “splitting”. The direct method samples independent errors at each iteration, while the splitting method (by Bravyi & Vargo) uses MCMC to determine the next error to sample. Ref: arXiv:1308.6270
- __init__(output_file: str, label='unlabelled', on_update: ~typing.Callable = <function identity>, update_frequency: int = 5, save_frequency: int = 1, method: str = 'direct', log_file: str | None = None, verbose: bool = True)
- append(simulation: BaseSimulation)
Append a simulation to the current BatchSimulation.
- Parameters:
simulation (BaseSimulation) – The simulation to append.
- estimate_remaining_time(n_trials: int)
Estimate remaining time given target n_trials.
- Parameters:
n_trials (int) – The target total number of trials.
- load_results()
Load results from disk.
- on_update(n_trials: int)
Function that gets called on every update. It uses the total number of runs, n_trials, to estimate the remaining time
- run(n_trials, progress: ~typing.Callable = <function identity>)
Perform the running.
- Parameters:
n_trials (int) – Number of trials to run.
progress (Callable) – The progress bar, such as tqdm.
- save_file()
Do a complete save of the file.
- property wall_time
Total time run so far.
- class panqec.simulation.DirectSimulation(code: StabilizerCode, error_model: BaseErrorModel, decoder: BaseDecoder, error_rate: float, compress: bool = True, verbose=True, rng=None)
Quantum Error Correction Simulation.
- Parameters:
code (StabilizerCode) – The code to simulate.
error_model (BaseErrorModel) – The error model to use.
decoder (BaseDecoder) – The decoder to use.
error_rate (float) – The error rate parameter.
compress (bool) – Set False to not compress the output files and save as plain json.
verbose (bool) – Set False to suppress output.
rng – Set Random number generator if you want to seed it.
- __init__(code: StabilizerCode, error_model: BaseErrorModel, decoder: BaseDecoder, error_rate: float, compress: bool = True, verbose=True, rng=None)
- get_results()
Return results as dictionary.
- class panqec.simulation.SplittingSimulation(code: StabilizerCode, error_model: BaseErrorModel, decoders: List[BaseDecoder], error_rates: List[float], n_init_runs: int, start_run: int = 0, compress: bool = True, verbose: bool = True, rng=None)
Quantum Error Correction Simulation.
- __init__(code: StabilizerCode, error_model: BaseErrorModel, decoders: List[BaseDecoder], error_rates: List[float], n_init_runs: int, start_run: int = 0, compress: bool = True, verbose: bool = True, rng=None)
- get_results()
Return results as dictionary.
- panqec.simulation.read_input_dict(data: dict, output_file: str, verbose: bool = True, *args, **kwargs) BatchSimulation
Return BatchSimulation from input dict.
- Parameters:
data (dict) – Data that has been parsed from an input json file.
- Returns:
batch_simulation – BatchSimulation object populated with the simulations specified in the input data.
- Return type:
- panqec.simulation.read_input_json(input_file: str, output_file: str, log_file: str | None = None) BatchSimulation
Read json input file or .json.gz file.
- panqec.simulation.run_file(input_file: str, output_file: str, n_trials: int, progress: ~typing.Callable = <function identity>, log_file: str | None = None, verbose: bool = True)
Run an input json file.
- Parameters:
input_file (str) – Path to the input json file.
output_file (str) – Path to the json file that will contain the results.
n_trials (int) – The number of MCMC trials to do.
progress (Callable) – Callable function
verbose (bool,) – Verbosity of the output
- Return type:
None
- panqec.simulation.run_once(code: StabilizerCode, error_model: BaseErrorModel, decoder: BaseDecoder, error_rate: float, rng=None) dict
Run a simulation once and return the results as a dictionary.