QkTargetEntry
typedef struct QkTargetEntry QkTargetEntry
A mapping of qubit arguments and properties representing gate map of the Target. This feature is used due to not having valid native mappings available from C.
Here’s an example of how this structure works:
#include <qiskit.h>
#include <math.h>
// Create a Target Entry for a CX Gate
QkTargetEntry *entry = qk_target_entry_new(QkGate_CX);
// Add mapping between (0,1) and properties duration of 10e-9 and unknown error.
uint32_t qargs[2] = {0, 1};
qk_target_entry_add(entry, qargs, 2, 10e-9, NAN);
// Add mapping between Global, and no set duration NAN and error of 0.003)
qk_target_entry_add(entry, NULL, 0, NAN, 0.003);
Functions
qk_target_entry_new
QkTargetEntry *qk_target_entry_new(QkGate operation)
Creates an entry to the QkTarget
based on a QkGate
instance with no parameters.
Example
QkTargetEntry *entry = qk_target_entry_new(QkGate_H);
If the instance of QkGate
uses fixed parameters, use qk_target_entry_new_fixed
. Regular parameters are not currently supported.
Parameters
operation – The QkGate
whose properties this target entry defines.
Returns
A pointer to the new QkTargetEntry
.
qk_target_entry_new_measure
QkTargetEntry *qk_target_entry_new_measure(void)
Creates a new entry for adding a measurement instruction to a QkTarget
.
Example
QkTargetEntry *entry = qk_target_entry_new_measure();
// Add fixed duration and error rates from qubits at index 0 to 4.
for (uint32_t i = 0; i < 5; i++) {
// Measure is a single qubit instruction
uint32_t qargs[1] = {i};
qk_target_entry_add_property(entry, qargs, 1, 1.928e-10, 7.9829e-11);
}
// Add the entry to a target with 5 qubits
QkTarget *measure_target = qk_target_new(5);
qk_target_add_instruction(measure_target, entry);
Returns
A pointer to the new QkTargetEntry
for a measurement instruction.
qk_target_entry_new_reset
QkTargetEntry *qk_target_entry_new_reset(void)
Creates a new entry for adding a reset instruction to a QkTarget
.
Example
QkTargetEntry *entry = qk_target_entry_new_reset();
// Add fixed duration and error rates from qubits at index 0 to 2.
for (uint32_t i = 0; i < 3; i++) {
// Reset is a single qubit instruction
uint32_t qargs[1] = {i};
qk_target_entry_add_property(entry, qargs, 1, 1.2e-11, 5.9e-13);
}
// Add the entry to a target with 3 qubits
QkTarget *reset_target = qk_target_new(3);
qk_target_add_instruction(reset_target, entry);
Returns
A pointer to the new QkTargetEntry
for a reset instruction.
qk_target_entry_new_fixed
QkTargetEntry *qk_target_entry_new_fixed(QkGate operation, double *params)
Creates an entry to the QkTarget
based on a QkGate
instance with no parameters.
Example
double crx_params[1] = {3.14};
QkTargetEntry *entry = qk_target_entry_new(QkGate_CRX, crx_params);
Safety
The params
type is expected to be a pointer to an array of double
where the length matches the the expectations of the QkGate
. If the array is insufficently long the behavior of this function is undefined as this will read outside the bounds of the array. It can be a null pointer if there are no params for a given gate. You can check qk_gate_num_params
to determine how many qubits are required for a given gate.
Adding a QkGate
with regular parameters is not currently supported.
Parameters
- operation – The
QkGate
whose properties this target entry defines. - params – A pointer to the parameters that the instruction is calibrated for.
Returns
A pointer to the new QkTargetEntry
.
qk_target_entry_num_properties
uintptr_t qk_target_entry_num_properties(const QkTargetEntry *entry)
Retrieves the number of properties stored in the target entry.
Example
// Create an entry for an H gate
QkTargetEntry *entry = qk_target_entry_new(QkGate_H);
size_t props_size = qk_target_entry_num_properties(entry);
Safety
The behavior is undefined if entry
is not a valid, non-null pointer to a QkTargetEntry
object.
Parameters
entry – The pointer to the mapping object.
Returns
The number of properties in the QkTargetEntry
.
qk_target_entry_free
void qk_target_entry_free(QkTargetEntry *entry)
Frees the entry.
Example
QkTargetEntry *entry = qk_target_entry_new(QkGate_H);
qk_target_entry_free(entry);
Safety
The behavior is undefined if entry
is not a valid, non-null pointer to a QkTargetEntry
object.
An entry pointer will be freed when added to a QkTarget
via qk_target_add_instruction
, this function is only meant to be used alternatively if an entry is never added to a QkTarget
instance.
Parameters
entry – The pointer to the mapping object to be freed.
qk_target_entry_add_property
QkExitCode qk_target_entry_add_property(QkTargetEntry *entry, uint32_t *qargs, uint32_t num_qubits, double duration, double error)
Adds an instruction property instance based on its assigned qargs.
Example
QkTargetEntry *entry = qk_target_entry_new(QkGate_CX);
uint32_t qargs[2] = {0, 1};
qk_target_entry_add_property(entry, qargs, 2, 0.0, 0.1);
Safety
The behavior is undefined if entry
is not a valid, non-null pointer to a QkTargetEntry
object.
Parameters
- entry – The pointer to the entry object.
- qargs – A pointer to the array of
uint32_t
qubit indices to add the gate on, can be a null pointer to check for global properties. - num_qubits – The length of the qargs array.
- duration – The instruction’s duration in seconds on the specific set of qubits.
- error – The instruction’s average error rate on the specific set of qubits.