qat.runtime.base module
- class BaseRuntime(engine, results_pipeline=None, connection_mode=<ConnectionMode.DEFAULT: 3>)
Bases:
ABC
Provides a Base class to build on for runtimes of varying complexities.
A runtime provides the means to execute quantum programs. It can take on various responsibilities, including interfacing the execution engine and post-processing of results. Runtimes are designed to fit a specific purpose. For example, the
SimpleRuntime
provides the means to execute already compiled programsExecutable
. In the future, there will be support for hybrid runtimes that take on both compilation and execution responsibilities.- Parameters:
engine¶ (
NativeEngine
) – The execution engine for a target machine.results_pipeline¶ (
Optional
[PassManager
]) – Optionally provided a pipeline for results processing. If not provided, a default pipeline is provided.connection_mode¶ (
ConnectionMode
) – Specifies how the connection is maintained.
- connect_engine(flag)
Connect the engine according to the connection mode.
- Return type:
bool
|None
- default_pipeline()
- disconnect_engine(flag)
Disconnect the engine according to the connection mode.
- Return type:
bool
|None
- abstract execute(*args)
- static number_of_batches(total_shots, shots_per_batch)
Calculates the number of shot batches to execute.
When the total number of shots exceeds the capabilities of the target machine, we can execute a number of batches with a subset of the shots. This number of shots should be calculated during compilation, and included in the executable. This method calculates number of batches to execute.
In the instance that the total number of shots cannot be batched into a whole number of the compiled shots, the runtime will execute more shots than required. If results are returned from the hardware per shot, then we can simply trim the results down to the required amount of shots. However, this cannot be done if the post-processing over the shots is done on the hardware. In this case, the program will be executed for
ceil(total_shots / shots_per_batch) * shots_per_batch
shots.If the compiled number of shots is zero, then it is assumed all shots can be achieved in a single batch.
- static validate_max_shots(shots)
- class ResultsAggregator(acquires)
Bases:
object
Aggregates the acquisition results from batching of shots.
Begin the aggregation of results for a list of acquisitions.
- Parameters:
acquires¶ (List[AcquireData]) – List of acquires to be collected.
- results(max_shots=None)
Returns the results normalized in an appropiate way.
For
AcquireMode.SCOPE
, results are averaged over batches. ForAcquireMode.RAW
orAcquireMode.INTEGRATOR
, a truncated amount ofmax_shots
shots are returned. IfNone
, then returns all shots.
- update(new_results)
Add a batch of results.
For
AcquireMode.RAW
andAcquireMode.INTEGRATOR
, this means to append the new results. ForAcquireMode.SCOPE
, results are accumulated as a sum.