qoolqit.execution
execution
Execute quantum programs on QPUs or local/remote emulators.
Modules:
-
BackendType–A module gathering all available backends.
-
backends–Backends to run quantum programs on local/remote emulators and QPUs.
-
compilation_functions– -
job–Job submission and results retrieval on local/remote emulators and QPUs.
-
sequence_compiler–
Classes:
-
BitStrings–Stores bitstrings sampled from the state at the evaluation times.
-
CorrelationMatrix–Stores the correlation matrix for the current state.
-
EmulationConfig–Configures an emulation on a backend.
-
Energy–Stores the energy of the system at the evaluation times.
-
EnergySecondMoment–Stores the expectation value of
H(t)^2at the evaluation times. -
EnergyVariance–Stores the variance of the Hamiltonian at the evaluation times.
-
Expectation–Stores the expectation of the given operator on the current state.
-
Fidelity–Stores the fidelity with a pure state at the evaluation times.
-
Job–Abstract representation of an asynchronous job or task.
-
LocalEmulator–Run QoolQit
QuantumPrograms on a Pasqal local emulator backends. -
Occupation–Stores the occupation number of an eigenstate on each qudit.
-
QPU–Execute QoolQit QuantumPrograms on Pasqal quantum processing units.
-
RemoteEmulator–Run QoolQit
QuantumPrograms on a Pasqal remote emulator backends. -
Results–A collection of results.
-
StateResult–Stores the quantum state at the evaluation times.
Functions:
-
get_batch_id–Return the batch ID associated with a remote job.
-
retrieve_remote_job–Retrieve a previously submitted remote job by its identifiers.
Attributes:
-
JobStatus(TypeAlias) –Alias for :class:
~pulser.backend.remote.JobStatus.
JobStatus: TypeAlias = remote.JobStatus
module-attribute
Alias for :class:~pulser.backend.remote.JobStatus.
Terminal states (where :meth:Job.has_ended returns True):
- :attr:
~remote.JobStatus.DONE - :attr:
~remote.JobStatus.ERROR - :attr:
~remote.JobStatus.CANCELED
-
API reference
qoolqit.execution
executionJobget_status
BitStrings(*, evaluation_times: Sequence[float] | None = None, num_shots: int | None = None, one_state: Eigenstate | None = None, tag_suffix: str | None = None)
Stores bitstrings sampled from the state at the evaluation times.
Error rates are taken from the NoiseModel passed to the backend via the EmulationConfig. The bitstrings are stored as a Counter[str].
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to sample bitstrings. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(num_shotsint | None, default:None) –How many bitstrings to sample each time this observable is computed. If left as
None, will usedefault_num_shotsof the backend'sEmulationConfig. -
(one_stateEigenstate | None, default:None) –The eigenstate that measures to 1. Can be left undefined if the state's eigenstates form a known eigenbasis with a defined "one state".
-
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
num_shots(int | None) –How many bitstrings to sample each time this observable is computed.
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/default_observables.py
num_shots: int | None
property
writable
How many bitstrings to sample each time this observable is computed.
Warning
The default value for this parameter was changed from 1000 to None
in Pulser v1.7. When left as None, it now relies on
EmulationConfig.default_num_shots to decide how many shots to
take.
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, config: EmulationConfig, state: State, **kwargs: Any) -> Counter[str]
Calculates the observable to store in the Results.
Source code in pulser/backend/default_observables.py
CorrelationMatrix(*, evaluation_times: Sequence[float] | None = None, one_state: Eigenstate | None = None, tag_suffix: str | None = None)
Stores the correlation matrix for the current state.
The correlation matrix is calculated as
[[<φ(t)|n_i n_j|φ(t)> for j in qubits] for i in qubits]
where n_k = |one_state><one_state|.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the correlation matrix. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(one_stateEigenstate | None, default:None) –The eigenstate to measure the population of in the correlation matrix. Can be left undefined if the state's eigenstates form a known eigenbasis with a defined "one state".
-
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/default_observables.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, hamiltonian: Operator, **kwargs: Any) -> list[list]
Calculates the observable to store in the Results.
Source code in pulser/backend/default_observables.py
EmulationConfig(*, callbacks: Sequence[Callback] = (), observables: Sequence[Observable] = (), default_evaluation_times: Sequence[SupportsFloat] | Literal['Full'] = (1.0,), initial_state: StateType | None = None, with_modulation: bool = False, interaction_matrix: ArrayLike | None = None, prefer_device_noise_model: bool = False, noise_model: NoiseModel | None = None, n_trajectories: int | None = None, default_num_shots: int = 1000, **backend_options: Any)
Configures an emulation on a backend.
Note
Additional parameters may be provided. It is up to the emulation
backend that receives a configuration with extra parameters to assess
whether it recognizes them and how it will use them. To know all
parameters expected by an EmulatorBackend, consult its associated
EmulationConfig subclass found under
EmulatorBackend.config_type.
Parameters:
-
(observablesSequence[Observable], default:()) –A sequence of observables to compute at specific evaluation times. The observables without specified evaluation times will use this configuration's 'default_evaluation_times'.
-
(callbacksSequence[Callback], default:()) –A general callback that is not an observable. Observables must be fed into the observables arg, since they all interact with the Results, and are subject to additional validation. Unlike observables, these are called at every emulation step.
-
(default_evaluation_timesSequence[SupportsFloat] | Literal['Full'], default:(1.0,)) –The default times at which observables are computed. Can be a sequence of unique relative times between 0 (the start of the sequence) and 1 (the end of the sequence), in ascending order. Can also be specified as "Full", in which case every step in the emulation will also be an evaluation time.
-
(initial_stateStateType | None, default:None) –The initial state from which emulation starts. If specified, the state type needs to be compatible with the emulator backend (i.e. it must match
EmulatorBackend.config_type.state_type). If left undefined, defaults to starting with all qudits in the ground state. -
(with_modulationbool, default:False) –Whether to emulate the sequence with the programmed input or the expected output.
-
(interaction_matrixArrayLike | None, default:None) –An optional interaction matrix to replace the interaction terms in the Hamiltonian. For an N-qudit system, must be an NxN symmetric matrix where entry (i, j) dictates the interaction coefficient between qudits i and j, ie it replaces the C_n/r_{ij}^n term.
-
(prefer_device_noise_modelbool, default:False) –If True, uses the noise model of the sequence's device (if the sequence's device has one), regardless of the noise model given with this configuration.
-
(noise_modelNoiseModel | None, default:None) –An optional noise model to emulate the sequence with. Ignored if the sequence's device has default noise model and
prefer_device_noise_model=True. -
(n_trajectoriesint | None, default:None) –The number of trajectories to average over when the emulation includes stochastic noise or is using a Monte Carlo solver. When left undefined:
(1) If 'prefer_device_noise_model=False', tries to use the (now deprecated) value of
NoiseModel.runs. If that is also not defined, defaults to 1 trajectory.(2) If 'prefer_device_noise_model=True', defaults to 40 trajectories.
-
(default_num_shotsint, default:1000) –The default number of shots for
BitStrings, used whenever the observable doesn't define its own. Defaults to 1000.
-
API reference
qoolqit.execution
executionEmulationConfigfrom_abstract_repr
Methods:
-
from_abstract_repr–Deserialize an EmulationConfig from an abstract JSON object.
-
is_evaluation_time–Assesses whether a relative time is an evaluation time.
-
is_time_in_evaluation_times–Checks if a time is within a collection of evaluation times.
-
operator_type–The preferred operator type to use with this config class.
-
state_type–The preferred state type to use with this config class.
-
to_abstract_repr–Serialize
EmulationConfigto a JSON formatted str. -
with_changes–Returns a copy of the config with the given changes.
Attributes:
-
callbacks(Sequence[Callback]) –A sequence of callbacks that are not observables.
-
default_evaluation_times(NDArray[floating[Any]] | Literal['Full']) –The default times at which observables are computed.
-
default_num_shots(int) –The default number of shots for
BitStrings. -
initial_state(StateType | None) –A custom initial state from which emulation starts.
-
interaction_matrix(AbstractArray | None) –An interaction matrix to replace the Hamiltonian interaction terms.
-
n_trajectories(int) –The number of trajectories to average over (when applicable).
-
noise_model(NoiseModel) –A custom noise model to emulate the sequence with.
-
observables(Sequence[Observable]) –A sequence of observables to compute at specific evaluation times.
-
prefer_device_noise_model(bool) –Whether to use the noise model of the sequence's
Device. -
with_modulation(bool) –Whether to emulate the sequence with output modulation effects.
Source code in pulser/backend/config.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
callbacks: Sequence[Callback]
instance-attribute
A sequence of callbacks that are not observables.
default_evaluation_times: NDArray[np.floating[Any]] | Literal['Full']
instance-attribute
The default times at which observables are computed.
default_num_shots: int
instance-attribute
The default number of shots for BitStrings.
initial_state: StateType | None
instance-attribute
A custom initial state from which emulation starts.
interaction_matrix: pm.AbstractArray | None
instance-attribute
An interaction matrix to replace the Hamiltonian interaction terms.
n_trajectories: int
instance-attribute
The number of trajectories to average over (when applicable).
noise_model: NoiseModel
instance-attribute
A custom noise model to emulate the sequence with.
observables: Sequence[Observable]
instance-attribute
A sequence of observables to compute at specific evaluation times.
prefer_device_noise_model: bool
instance-attribute
Whether to use the noise model of the sequence's Device.
with_modulation: bool
instance-attribute
Whether to emulate the sequence with output modulation effects.
from_abstract_repr(obj_str: str) -> EmulationConfig
classmethod
Deserialize an EmulationConfig from an abstract JSON object.
Parameters:
-
(obj_strstr) –The JSON string representing the config encoded in the abstract JSON format.
Returns:
-
EmulationConfig(EmulationConfig) –The EmulationConfig instance.
Source code in pulser/backend/config.py
is_evaluation_time(t: float, tol: float = 1e-06) -> bool
Assesses whether a relative time is an evaluation time.
Source code in pulser/backend/config.py
is_time_in_evaluation_times(t: float, evaluation_times: ArrayLike, tol: float = 1e-06) -> bool
staticmethod
Checks if a time is within a collection of evaluation times.
Source code in pulser/backend/config.py
operator_type() -> Type[Operator]
state_type() -> Type[State]
to_abstract_repr(skip_validation: bool = False) -> str
Serialize EmulationConfig to a JSON formatted str.
Source code in pulser/backend/config.py
with_changes(**changes: Any) -> Self
Energy(*, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the energy of the system at the evaluation times.
The energy is calculated as the expectation value of the Hamiltonian,
i.e. <φ(t)|H(t)|φ(t)>.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the energy. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/observable.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, hamiltonian: Operator, **kwargs: Any) -> Any
EnergySecondMoment(*, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the expectation value of H(t)^2 at the evaluation times.
Useful for computing the variance when averaging over many executions of the program.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the variance. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/observable.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, hamiltonian: Operator, **kwargs: Any) -> Any
Calculates the observable to store in the Results.
Source code in pulser/backend/default_observables.py
EnergyVariance(*, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the variance of the Hamiltonian at the evaluation times.
The variance of the Hamiltonian at time t is calculated by
<φ(t)|H(t)^2|φ(t)> - <φ(t)|H(t)|φ(t)>^2
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the variance. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/observable.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, hamiltonian: Operator, **kwargs: Any) -> Any
Calculates the observable to store in the Results.
Source code in pulser/backend/default_observables.py
Expectation(operator: Operator, *, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the expectation of the given operator on the current state.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the expectation value. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(operatorOperator) –The operator to measure. Must be of the appropriate type for the backend.
-
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/default_observables.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, **kwargs: Any) -> Any
Fidelity(state: State, *, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the fidelity with a pure state at the evaluation times.
The fidelity uses the overlap between the given state and the state of
the system at each evaluation time. For pure states, this corresponds
to |<ψ|φ(t)>|^2 for the given state |ψ> and the state |φ(t)>
obtained by time evolution.
Parameters:
-
(stateState) –The state
|ψ>. Note that this must be of an appropriate type for the backend. -
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the fidelity. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/default_observables.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, **kwargs: Any) -> Any
Job
Abstract representation of an asynchronous job or task.
A :class:Job tracks the lifecycle of a unit of work submitted
for execution. It provides methods to inspect its state, wait for
its result, and cancel it.
Lifecycle::
PENDING -> RUNNING -> DONE
-> ERROR
-> CANCELED
Concrete backend implementations (:class:_LocalJob,
:class:_RemoteJob) must override all abstract methods.
The leading underscore in their names indicates that they are
internal to the library and must not be instantiated or
referenced directly by library consumers.
Instead, obtain a :class:Job from a backend submission
function such as backend.run(program).
Note
A submitted job is not necessarily asynchronous. Whether
execution is synchronous or asynchronous depends on the
function that creates and returns the :class:Job instance
(e.g. a local backend may execute synchronously and return
an already-completed job, while a remote backend submits
the work and returns a job that must be polled).
-
API reference
qoolqit.execution
executionretrieve_remote_job
-
API reference
qoolqit.execution
executionget_batch_id
Methods:
-
cancel–Request cancellation of the job.
-
get_status–Return the current lifecycle state of the job.
-
has_ended–Return whether the job has reached a terminal state.
-
job_id–Return the unique identifier of the job.
-
results–Block until the job completes and return its result.
cancel() -> None
abstractmethod
Request cancellation of the job.
Has no effect if the job has already reached a terminal state.
After a successful cancellation, :meth:get_status returns
:attr:~remote.JobStatus.CANCELED and :meth:has_ended returns
True.
Note
Some implementations do not support cancellation. In that
case this method is a no-op and the job status will never
be :attr:~remote.JobStatus.CANCELED.
Source code in qoolqit/execution/job.py
get_status() -> JobStatus
abstractmethod
Return the current lifecycle state of the job.
Returns:
-
JobStatus(JobStatus) –The current state of the job.
has_ended() -> bool
Return whether the job has reached a terminal state.
A job has ended when its status is one of
:attr:~remote.JobStatus.DONE, :attr:~remote.JobStatus.ERROR, or
:attr:~remote.JobStatus.CANCELED.
Returns:
-
bool(bool) –Trueif the job is in a terminal state, -
bool–Falseotherwise.
Source code in qoolqit/execution/job.py
job_id() -> str
abstractmethod
Return the unique identifier of the job.
For remote jobs this is the UUID used to track the job in the PASQAL Cloud Portal. For local jobs this is currently an empty string.
Returns:
-
str(str) –A string uniquely identifying this job.
Source code in qoolqit/execution/job.py
results(timeout: float = math.inf) -> ResultType
abstractmethod
Block until the job completes and return its result.
Waits until the job reaches a terminal state, then returns the result. Polling strategy (interval, backoff) is delegated to the underlying connection.
Parameters:
-
(timeoutfloat, default:inf) –Maximum seconds to wait. Defaults to
math.inf(wait indefinitely).
Returns:
-
ResultType(ResultType) –The result produced by the job.
Raises:
-
TimeoutError–If the job does not complete within timeout seconds.
-
JobFailedError–If the job reached a failed or error state.
-
JobCancelledError–If the job was cancelled.
Source code in qoolqit/execution/job.py
LocalEmulator(*, backend_type: type[EmulatorBackend] = QutipBackendV2, emulation_config: EmulationConfig | None = None, num_shots: int | None = None)
Run QoolQit QuantumPrograms on a Pasqal local emulator backends.
This class serves as a primary interface between tools written using QoolQit (including solvers) and local emulator backends.
Parameters:
-
(backend_typetype, default:QutipBackendV2) –backend type. Must be a subtype of
pulser.backend.EmulatorBackend. -
(emulation_configEmulationConfig, default:None) –optional configuration object emulators.
-
(num_shotsint, default:None) –number of bitstring samples to collect from the final quantum state.
Examples:
from qoolqit.execution import LocalEmulator, BackendType
backend = LocalEmulator(backend_type=BackendType.QutipBackendV2)
result = backend.run(program)
Methods:
-
default_emulation_config–Return a unique emulation config for all emulators.
-
run–Run a compiled QuantumProgram and return the results.
-
validate_emulation_config–Returns a valid config for emulator backends, if needed.
Source code in qoolqit/execution/backends.py
default_emulation_config() -> EmulationConfig
Return a unique emulation config for all emulators.
Defaults to a configuration that asks for the final bitstring, sampled num_shots times.
Source code in qoolqit/execution/backends.py
run(program: QuantumProgram) -> job.Job[Results]
Run a compiled QuantumProgram and return the results.
Source code in qoolqit/execution/backends.py
validate_emulation_config(emulation_config: EmulationConfig | None) -> EmulationConfig
Returns a valid config for emulator backends, if needed.
Parameters:
-
(emulation_configEmulationConfig | None) –optional base configuration class for all emulators backends. If no config is provided to an emulator backend, the backend default will used.
Source code in qoolqit/execution/backends.py
Occupation(*, evaluation_times: Sequence[float] | None = None, one_state: Eigenstate | None = None, tag_suffix: str | None = None)
Stores the occupation number of an eigenstate on each qudit.
For every qudit i, calculates <φ(t)|n_i|φ(t)>, where
n_i = |one_state><one_state|.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to compute the correlation matrix. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(one_stateEigenstate | None, default:None) –The eigenstate to measure the population of. Can be left undefined if the state's eigenstates form a known eigenbasis with a defined "one state".
-
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/default_observables.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: State, hamiltonian: Operator, **kwargs: Any) -> list
Calculates the observable to store in the Results.
Source code in pulser/backend/default_observables.py
QPU(*, connection: RemoteConnection, num_shots: int | None = None)
Execute QoolQit QuantumPrograms on Pasqal quantum processing units.
This class provides the primary interface for running quantum programs on actual QPU hardware. It requires authenticated credentials through a connection object to submit and execute programs on remote quantum processors.
Parameters:
-
(connectionRemoteConnection) –Authenticated connection to the remote QPU backend.
-
(num_shotsint | None, default:None) –Number of bitstring samples to collect from the final quantum state.
Examples:
Using Pasqal Cloud:
from pulser_pasqal import PasqalCloud
from qoolqit.execution import QPU
connection = PasqalCloud(
username="your_username",
password="your_password",
project_id="your_project_id"
)
backend = QPU(connection=connection)
remote_results = backend.submit(program)
Using Atos MyQML:
from pulser_myqlm import PulserQLMConnection
from qoolqit.execution import QPU
connection = PulserQLMConnection()
backend = QPU(connection=connection)
results = backend.run(program)
Note
Contact your quantum computing provider for credentials and connection setup: - Pasqal Cloud Documentation - Atos MyQML Framework
Methods:
-
run–Run a compiled QuantumProgram and return a job handler.
-
validate_connection–Validate the required connection to instantiate a RemoteBackend.
Source code in qoolqit/execution/backends.py
run(program: QuantumProgram) -> job.Job[Results]
Run a compiled QuantumProgram and return a job handler.
The returned handler Job can be used to retrieve results with job.results()
Parameters:
-
(programQuantumProgram) –the compiled quantum program to run.
Source code in qoolqit/execution/backends.py
validate_connection(connection: RemoteConnection) -> RemoteConnection
staticmethod
Validate the required connection to instantiate a RemoteBackend.
Remote emulators and QPUs require a pulser.backend.remote.RemoteConnection or derived
to send jobs. Validation also happens inside the backend. Early validation just makes the
error easier to understand.
Source code in qoolqit/execution/backends.py
RemoteEmulator(*, backend_type: type[RemoteEmulatorBackend] = EmuFreeBackendV2, connection: RemoteConnection, emulation_config: EmulationConfig | None = None, num_shots: int | None = None)
Run QoolQit QuantumPrograms on a Pasqal remote emulator backends.
This class serves as a primary interface between tools written using QoolQit (including solvers)
and remote emulator backends.
The behavior is similar to LocalEmulator, but here, requires credentials through
a connection to submit/run a program.
To get your credentials and to create a connection object, please refer to the Pasqal Cloud
interface documentation.
Parameters:
-
(backend_typetype, default:EmuFreeBackendV2) –backend type. Must be a subtype of
pulser_pasqal.backends.RemoteEmulatorBackend. -
(connectionRemoteConnection) –connection to execute the program on remote backends.
-
(emulation_configEmulationConfig, default:None) –optional configuration object emulators.
-
(num_shotsint, default:None) –number of bitstring samples to collect from the final quantum state.
Examples:
from pulser_pasqal import PasqalCloud
from qoolqit.execution import RemoteEmulator, BackendType
connection = PasqalCloud(username=..., password=..., project_id=...)
backend = RemoteEmulator(backend_type=BackendType.EmuFreeBackendV2, connection=connection)
Methods:
-
default_emulation_config–Return a unique emulation config for all emulators.
-
run–Run a compiled QuantumProgram and return a job handler.
-
validate_connection–Validate the required connection to instantiate a RemoteBackend.
-
validate_emulation_config–Returns a valid config for emulator backends, if needed.
Source code in qoolqit/execution/backends.py
default_emulation_config() -> EmulationConfig
Return a unique emulation config for all emulators.
Defaults to a configuration that asks for the final bitstring, sampled num_shots times.
Source code in qoolqit/execution/backends.py
run(program: QuantumProgram) -> job.Job[Results]
Run a compiled QuantumProgram and return a job handler.
The returned handler Job can be used to retrieve results with job.results()
Parameters:
-
(programQuantumProgram) –the compiled quantum program to run.
Source code in qoolqit/execution/backends.py
validate_connection(connection: RemoteConnection) -> RemoteConnection
staticmethod
Validate the required connection to instantiate a RemoteBackend.
Remote emulators and QPUs require a pulser.backend.remote.RemoteConnection or derived
to send jobs. Validation also happens inside the backend. Early validation just makes the
error easier to understand.
Source code in qoolqit/execution/backends.py
validate_emulation_config(emulation_config: EmulationConfig | None) -> EmulationConfig
Returns a valid config for emulator backends, if needed.
Parameters:
-
(emulation_configEmulationConfig | None) –optional base configuration class for all emulators backends. If no config is provided to an emulator backend, the backend default will used.
Source code in qoolqit/execution/backends.py
Results(atom_order: tuple[str, ...], total_duration: int)
dataclass
A collection of results.
Parameters:
-
(atom_ordertuple[str, ...]) –The order of the atoms/qudits in the results.
-
(total_durationint) –The total duration of the sequence, in ns.
Methods:
-
aggregate–Aggregate a Sequence of Results objects into a single Results.
-
from_abstract_repr–Deserializes a Results object from json.
-
get_result–Get the a specific result at a given time.
-
get_result_tags–Get a list of results tags present in this object.
-
get_result_times–Get a list of times for which the given result has been stored.
-
get_tagged_results–Gets the results for every tag.
-
to_abstract_repr–Serializes this object into a json string.
Attributes:
-
atom_order(tuple[str, ...]) –The order of the atoms/qudits in the results.
-
final_bitstrings(dict[str, int]) –The bitstrings at the end of the sequence, if available.
-
final_state(State) –The state at the end of the sequence, if available.
-
total_duration(int) –The total duration of the sequence, in ns.
atom_order: tuple[str, ...]
instance-attribute
The order of the atoms/qudits in the results.
final_bitstrings: dict[str, int]
property
The bitstrings at the end of the sequence, if available.
final_state: State
property
The state at the end of the sequence, if available.
total_duration: int
instance-attribute
The total duration of the sequence, in ns.
aggregate(results_to_aggregate: typing.Sequence[Results], **aggregation_functions: Callable[[Any], Any]) -> Results
classmethod
Aggregate a Sequence of Results objects into a single Results.
This is meant to accumulate the results of several runs with different noise trajectories into a single averaged Results. By default, results are averaged, with the exception of BitStrings, where the counters are joined. StateResult and EnergyVariance are not supported by default.
Warning
The ability to access a result from an observable instance (e.g. via Results.get_result(obs)) is only preserved if all aggregated results originated from the same observable instance. When that is not the case, the aggregated result can still be accessed via the observable's tag.
Parameters:
-
(results_to_aggregateSequence[Results]) –The list of Results to aggregate
Other Parameters:
-
observable_tag–Overrides the default aggregator. The argument name should be the tag of the Observable. The value is a Callable taking a list of the type to aggregate. Note that this does not override the default aggregation behaviour of the aggregated results.
Returns:
-
Results–The averaged Results object
Source code in pulser/backend/results.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
from_abstract_repr(repr: str) -> Results
classmethod
Deserializes a Results object from json.
Returns:
-
Results–The deserialized Results object.
Source code in pulser/backend/results.py
get_result(observable: Observable | str, time: float) -> Any
Get the a specific result at a given time.
Parameters:
-
(observableObservable | str) –The observable instance used to calculate the result or its tag.
-
(timefloat) –Relative time at which to get the result.
Returns:
-
Any–The result.
Source code in pulser/backend/results.py
get_result_tags() -> list[str]
get_result_times(observable: Observable | str) -> list[float]
Get a list of times for which the given result has been stored.
Parameters:
-
(observableObservable | str) –The observable instance used to calculate the result or its tag.
Returns:
-
list[float]–List of relative times.
Source code in pulser/backend/results.py
get_tagged_results() -> dict[str, list[Any]]
Gets the results for every tag.
Returns:
-
dict[str, list[Any]]–A mapping between a tag and the results associated to it,
-
dict[str, list[Any]]–at every evaluation time.
Source code in pulser/backend/results.py
to_abstract_repr(skip_validation: bool = False) -> str
Serializes this object into a json string.
Numpy arrays and torch Tensors are converted into lists, and their original class is lost forever.
Parameters:
-
(skip_validationbool, default:False) –Whether to skip validating the json against the schema used for deserialization.
Returns:
-
str–The json string
Source code in pulser/backend/results.py
StateResult(*, evaluation_times: Sequence[float] | None = None, tag_suffix: str | None = None)
Stores the quantum state at the evaluation times.
Parameters:
-
(evaluation_timesSequence[float] | None, default:None) –The relative times at which to store the state. If left as
None, uses thedefault_evaluation_timesof the backend'sEmulationConfig. -
(tag_suffixstr | None, default:None) –An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
Methods:
-
__call__–Specifies a call to the observable at a specific time.
-
apply–Calculates the observable to store in the Results.
Attributes:
-
tag(str) –Label for the observable, used to index the Results object.
-
uuid(UUID) –A universal unique identifier for this instance.
Source code in pulser/backend/observable.py
tag: str
property
Label for the observable, used to index the Results object.
Within a Results instance, all computed observables must have different tags.
Returns:
-
str–The tag of the observable.
uuid: uuid.UUID
property
A universal unique identifier for this instance.
__call__(config: EmulationConfig, t: float, state: State, hamiltonian: Operator, result: Results) -> None
Specifies a call to the observable at a specific time.
This is called after each time step performed by the emulator.
By default it calls apply() to compute a result and put it in Results
if t in self.evaluation_times.
It can be overloaded to define general callbacks that don't put results
in the Results object.
Parameters:
-
(configEmulationConfig) –The config object passed to the backend.
-
(tfloat) –The relative time as a float between 0 and 1.
-
(stateState) –The current state.
-
(hamiltonianOperator) –The Hamiltonian at this time.
-
(resultResults) –The Results object to store the result in.
Source code in pulser/backend/observable.py
apply(*, state: StateType, **kwargs: Any) -> StateType
get_batch_id(job: Job[Results]) -> str
Return the batch ID associated with a remote job.
Temporary utility for cases where batch_id must be persisted
and later passed to :func:retrieve_remote_job. Will be
deprecated once RemoteConnection supports direct job lookup
by job ID alone.
Parameters:
Returns:
-
str(str) –The batch ID if job is a :class:
_RemoteJob, -
str–otherwise an empty string.
Source code in qoolqit/execution/job.py
retrieve_remote_job(connection: remote.RemoteConnection, job_id: str, *, batch_id: str = '') -> Job[Results]
Retrieve a previously submitted remote job by its identifiers.
Use this to reconnect to a job in a new session, or to monitor a job submitted outside the current context.
Note
The batch_id argument is required by some
RemoteConnection implementations (e.g.
PasqalCloudConnection) to query job progress. Use
:func:get_batch_id to recover the batch ID from an existing
:class:Job if needed.
This dependency on batch_id is temporary and will be removed
once RemoteConnection supports direct lookup by job ID
alone.
Parameters:
-
(connectionRemoteConnection) –The remote connection through which to query the job.
-
(job_idstr) –The UUID of the job to retrieve.
-
(batch_idstr, default:'') –The batch identifier the job belongs to. Defaults to an empty string.
Returns: