qat.core.Job
- class qat.core.Job(psi_0=None, parameter_map=None, **kwargs)
A high level wrapper for the Job thrift class.
- Instance attributes:
circuit (
Circuit
): circuit to executeschedule (Schedule): schedule to execute
type (
ProcessingType
): type of Jobobservable (
Observable
, optional): the observable (required if job type is of type 1, i.e observable sampling)qubits (list<int>, optional): measured qubits
nbshots (int): number of required shots: if 0, do maximal number of shots
aggregate_data (bool): contract corresponding result object
amp_threshold (float, optional): amplitude values under this threshold are considered null
parameter_map (dict[str, complex], optional): read-only attribute containing all the binded variables with their values
meta_data (dict[str, str], optional): job meta_data
- compile(stack=None, specs=None)
Compiles the job given some QPU or stack.
If the first argument is a QPU, then this call is equivalent to:
qpu.compile(job)
Otherwise, if the first argument is a Plugin, this is equivalent to:
plugin.compile(job, specs)
- Parameters
stack (
QPUHandler
orAbstractPlugin
) – a plugin or a qpuspecs (optional,
HardwareSpecs
) – optionally, some specs (only used when qpu is a Plugin)
- Returns
- a compiled job or a batch of jobs if the compilation produced
several jobs
- Return type
- differentiate(vname, method=None, **kwargs)
Generates a collection of variational jobs such that the sum of their energies equates the partial derivative of the job’s energy w.r.t to a given variable.
\[\frac{\partial }{\partial \theta_j} \langle \psi(\theta) | H | \psi(\theta) \rangle = \sum_i \langle\psi_i(\theta) | H_i |\psi_i(\theta) \rangle\]where \((|\psi\rangle, H)\) is the input job and \((|\psi_i\rangle, H_i)\) are the output jobs.
Supported methods are:
shift-rule uses the chain rule for product differentiation together with a shift rule. This method generates \(2k\) jobs where \(k\) is the number of rotations parametrized by the variable.
h-test performs a Hadamard test and a modifies the observable to sample in order to encode the appropriate post-selection induced by the Hadamard test. It generates \(k\) jobs where \(k\) is the number of rotations parametrized by the variable. These jobs have an additional qubit and have observables that are (at most) twice as large as the initial observable.
- Parameters
vname (str) – a variable name.
method (str, optional) – the method to use. Default ‘shift-rule’.
kwargs (dict) – any additional parameter that can be passed to the differentiation method.
- Returns
a list of jobs
- Return type
list<Job>
Warning
The method can be called only on a job containing an observable.
- dump(fname)
Dumps the job in a binary file.
- Parameters
fname (str) – the file name
- eval(parameters=None, qpu=None)
Runs the job for a given (possibly empty) list of parameters and unpacks the result into a real value.
These two pieces of code are equivalent:
value = job.eval(x=x, qpu=qpu)
job_to_run = job(**{v: p for v, p in zip(job.get_variables(), x)}) value = qpu.submit(job).value.real
- Parameters
parameters (optional, np.array) – an array of values (should be of same length as job.get_variables())
qpu (optional,
QPUHandler
) – the QPU to use for the evaluation
- Returns
the result of the job evaluation
- Return type
float or Result
- classmethod from_bytes(data: bytes)
Builds a job from raw bytes object
- classmethod from_thrift(tobject)
Builds a Job from a thrift job
- get_variables()
Returns the sorted list of all variables appearing in the job
- gradient(method=None, **kwargs)
Generates a collection of groups of jobs such that the sum of the energy of each group equates the partial derivative of the job’s energy w.r.t each of its variable.
The collection is returned as a map mapping variable names to job list.
This method has several backends, see
differentiate()
for more details.- Parameters
method (str, optional) – the differentiation method
kwargs (dict) – additional arguments passed to the differentiation method
- Returns
a map associating variable names to list of jobs
- Return type
map<str, list<Job>>
- classmethod load(fname)
Loads the Job from a binary file.
- Parameters
fname (str) – the file name
- Returns
- property parameter_map: dict
Get the parameter map stored in a thrift dictionary
- Returns
dictionary of binded variables
- Return type
dict[str, complex]
- property psi_0
Get initial state
- Returns
the initial state
- Return type
str or np.ndarray
- run(qpu=None, meta_data=None)
Runs the job on a qpu.
The two following lines of code are equivalent:
result = job.run(qpu) # and result = qpu.submit(job)
- Parameters
qpu (optional,
QPUHandler
) – the target qpu. If None, import the default qpu (viaget_default_qpu()
)- Returns
a result
- Return type
- shift_qbits(offset)
Shifts the job’s qbits by a given offset. Consequently icreases the number of qubits of the job by the same offset.
Acts in place.
- Parameters
offset (int) – the offset
- property threshold
Computes the probability threshold. States having a probaility lower than this value must be removed from the result
- Returns
probability threshold
- Return type
float
- to_cpp()
Cast the Job into a Thrift object not meant for serialized transmission, but rather for C++ code.
- to_thrift()
Cast the Job into a pure Thrift object