QuantumProgram¶
Bases: Displayable
A container for the main quantum program to be executed.
At its core, a QuantumProgram is an
InstructionStack to run, a collection of all possible
Instruction objects that could be run (either "global"
or patch-based), and default noise model and RNG seeds.
Once the run command has been used, it also contains
a collection of History objects for each shot.
Examples:
>>> from loqs.core import QuantumProgram
>>> prog = QuantumProgram(instruction_stack=[], name="MyProgram")
>>> prog.name
'MyProgram'
QuantumProgram ¶
QuantumProgram(instruction_stack: InstructionStackLike = None, initial_history: HistoryLike = None, default_noise_model: BaseNoiseModel | str | None = None, default_base_seed: int | None = None, expiring_state: bool = True, global_instructions: Mapping[str, Instruction] | None = None, state_type: type[BaseQuantumState] | None = None, patch_types: Mapping[str, QECCode] | None = None, override_global_instructions: bool = False, name: str = '(Unnamed quantum program)') -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction_stack
|
InstructionStackLike
|
A list of |
None
|
initial_history
|
HistoryLike
|
An initial |
None
|
default_noise_model
|
BaseNoiseModel | str | None
|
A noise model to pass to any |
None
|
default_base_seed
|
int | None
|
Base seed to use for RNG. Each shot will use a seed as
|
None
|
expiring_state
|
bool
|
Whether to set |
True
|
global_instructions
|
Mapping[str, Instruction] | None
|
A list of |
None
|
state_type
|
type[BaseQuantumState] | None
|
The state type to use when constructing the |
None
|
patch_types
|
Mapping[str, QECCode] | None
|
A dict of name keys and |
None
|
override_global_instructions
|
bool
|
Whether or not to override |
False
|
name
|
str
|
Name for logging |
'(Unnamed quantum program)'
|
decode¶
Inherited static method from Serializable.decode().
display¶
Inherited method from Displayable.display().
dump¶
Inherited method from Serializable.dump().
encode¶
Inherited static method from Serializable.encode().
from_quantum_program
classmethod
¶
from_quantum_program(other: QuantumProgram, instruction_stack: InstructionStackLike = None, default_noise_model: BaseNoiseModel | str | None = None, default_base_seed: int | None = None, global_instructions: Mapping[str, Instruction] | None = None, state_type: type[BaseQuantumState] | None = None, patch_types: Mapping[str, QECCode] | None = None, name: str | None = None) -> QuantumProgram
Create a copy of a QuantumProgram with some options updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QuantumProgram
|
The base |
required |
instruction_stack
|
InstructionStackLike
|
See |
None
|
default_noise_model
|
BaseNoiseModel | str | None
|
See |
None
|
default_base_seed
|
int | None
|
See |
None
|
global_instructions
|
Mapping[str, Instruction] | None
|
See |
None
|
state_type
|
type[BaseQuantumState] | None
|
See |
None
|
patch_types
|
Mapping[str, QECCode] | None
|
See |
None
|
name
|
str | None
|
See |
None
|
Returns:
| Type | Description |
|---|---|
QuantumProgram
|
The copied and updated |
load¶
Inherited class method from Serializable.load().
read¶
Inherited class method from Serializable.read().
run ¶
run(num_shots: int = 1, max_frame_limit: int | None = None, shot_executor: SubmitExecutor | None = None, verbose: bool = True, checkpoint: bool = False, resume: bool = False, checkpoint_batch_size: int | None = None, checkpoint_dir: str | Path | None = None, force_resume: bool = False, n_shot_batches: int | None = None, results_filename: str = 'results.h5', progress_callback: Callable[[int, int], None] | None = None) -> ProgramResults
Execute some shots of this QuantumProgram.
This returns a ProgramResults object containing the shot histories and wall-clock timing metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_shots
|
int
|
The number of shots to execute. |
1
|
max_frame_limit
|
int | None
|
A maximum number of frames to execute before terminating.
The default |
None
|
shot_executor
|
SubmitExecutor | None
|
A |
None
|
verbose
|
bool
|
Whether to write a progress bar ( |
True
|
checkpoint
|
bool
|
Whether to durably checkpoint shots to disk as they complete
( |
False
|
resume
|
bool
|
Whether this call continues a prior checkpoint-enabled call
against the same checkpoint_batch_size:
Number of shots to accumulate, per writer, before durably
flushing them to disk. Only
meaningful when |
False
|
checkpoint_dir
|
str | Path | None
|
Directory to store checkpoint files. If None (default), checkpoints
are stored in a |
None
|
force_resume
|
bool
|
When resuming a checkpoint-enabled call (rerunning against a
|
False
|
n_shot_batches
|
int | None
|
Number of batches to split shots into. A batch count, not a size
(e.g. |
None
|
results_filename
|
str
|
Filename to use for the canonical results checkpoint file.
Defaults to "results.h5". Only relevant when |
'results.h5'
|
progress_callback
|
Callable[[int, int], None] | None
|
Optional callable invoked as |
None
|
Returns:
| Type | Description |
|---|---|
ProgramResults
|
A |
serialize_function¶
Inherited static method from Serializable.serialize_function().
write¶
Inherited method from Serializable.write().