DQCsim
Public Member Functions | Protected Member Functions | Friends | List of all members
dqcsim::wrap::PluginState Class Reference

Wrapper for DQCsim's internal plugin state within the context of downstream-synchronous plugin callbacks. More...

Inheritance diagram for dqcsim::wrap::PluginState:
dqcsim::wrap::UpstreamPluginState dqcsim::wrap::RunningPluginState

Public Member Functions

 PluginState (const PluginState &)=delete
 
void operator= (const PluginState &)=delete
 
 PluginState (PluginState &&)=delete
 
PluginStateoperator= (PluginState &&)=delete
 
QubitSet allocate (size_t num_qubits, ArbCmdQueue &&cmds)
 Allocates a number of downstream qubits, copying in the given command queue as arbitrary additional data for the qubits. More...
 
QubitSet allocate (size_t num_qubits, ArbCmdQueue &cmds)
 Allocates a number of downstream qubits, moving in the given command queue as arbitrary additional data for the qubits. More...
 
QubitSet allocate (size_t num_qubits)
 Allocates a number of default downstream qubits. More...
 
QubitRef allocate (ArbCmdQueue &&cmds)
 Allocates a single downstream qubit, copying in the given command queue as arbitrary additional data for the qubits. More...
 
QubitRef allocate (ArbCmdQueue &cmds)
 Allocates a single downstream qubit, moving in the given command queue as arbitrary additional data for the qubits. More...
 
QubitRef allocate ()
 Allocates a single downstream qubit. More...
 
void free (QubitSet &&qubits)
 Frees the given downstream qubits. More...
 
void free (const QubitSet &qubits)
 Frees the given downstream qubits. More...
 
void free (const QubitRef &qubit)
 Frees the given downstream qubit. More...
 
void gate (Gate &&gate)
 Sends a gate to the downstream plugin. More...
 
void gate (const Matrix &matrix, const QubitRef &q)
 Shorthand for sending a single-qubit gate to the downstream plugin. More...
 
void gate (const Matrix &matrix, const QubitRef &qa, const QubitRef &qb)
 Shorthand for sending a two-qubit gate to the downstream plugin. More...
 
void gate (const Matrix &matrix, const QubitRef &qa, const QubitRef &qb, const QubitRef &qc)
 Shorthand for sending a three-qubit gate to the downstream plugin. More...
 
void measure_x (const QubitRef &q)
 Shorthand for sending a single-qubit X-axis measurement to the downstream plugin. More...
 
void measure_x (const QubitSet &qs)
 Shorthand for sending a multi-qubit X-axis measurement to the downstream plugin. More...
 
void measure_y (const QubitRef &q)
 Shorthand for sending a single-qubit Y-axis measurement to the downstream plugin. More...
 
void measure_y (const QubitSet &qs)
 Shorthand for sending a multi-qubit Y-axis measurement to the downstream plugin. More...
 
void measure_z (const QubitRef &q)
 Shorthand for sending a single-qubit Z-axis measurement to the downstream plugin. More...
 
void measure_z (QubitSet &&qs)
 Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin. More...
 
void measure_z (const QubitSet &qs)
 Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin. More...
 
Cycle advance (Cycle cycles)
 Tells the downstream plugin to run for the specified number of cycles. More...
 
ArbData arb (ArbCmd &&cmd)
 Sends an arbitrary command downstream. More...
 
ArbData arb (const ArbCmd &cmd)
 Sends an arbitrary command downstream. More...
 
Measurement get_measurement (const QubitRef &qubit)
 Returns the latest measurement of the given downstream qubit. More...
 
Cycle get_cycles_since_measure (const QubitRef &qubit)
 Returns the number of downstream cycles since the latest measurement of the given downstream qubit. More...
 
Cycle get_cycles_between_measures (const QubitRef &qubit)
 Returns the number of downstream cycles between the last two measurements of the given downstream qubit. More...
 
Cycle get_cycle ()
 Returns the current value of the downstream cycle counter. More...
 
- Public Member Functions inherited from dqcsim::wrap::UpstreamPluginState
 UpstreamPluginState (const UpstreamPluginState &)=delete
 
void operator= (const UpstreamPluginState &)=delete
 
 UpstreamPluginState (UpstreamPluginState &&)=delete
 
UpstreamPluginStateoperator= (UpstreamPluginState &&)=delete
 
double random_f64 () noexcept
 Generates a random floating point number using the simulator random seed. More...
 
uint64_t random_u64 () noexcept
 Generates a random integer using the simulator random seed. More...
 
template<typename T >
random () noexcept
 Generates a random value using the simulator random seed. More...
 

Protected Member Functions

 PluginState (raw::dqcs_plugin_state_t state)
 Hidden constructor, only to be used by the callback wrappers.
 
- Protected Member Functions inherited from dqcsim::wrap::UpstreamPluginState
 UpstreamPluginState (raw::dqcs_plugin_state_t state)
 Hidden constructor, only to be used by the callback wrappers.
 

Friends

class CallbackEntryPoints
 

Additional Inherited Members

- Protected Attributes inherited from dqcsim::wrap::UpstreamPluginState
const raw::dqcs_plugin_state_t state
 The wrapped plugin state. More...
 

Detailed Description

Wrapper for DQCsim's internal plugin state within the context of downstream-synchronous plugin callbacks.

Cannot be moved or copied, as it must stay in scope of the plugin callbacks. Can also not be constructed except for by the callback wrapper classes.

Definition at line 6128 of file dqcsim.

Member Function Documentation

◆ allocate() [1/6]

QubitSet dqcsim::wrap::PluginState::allocate ( size_t  num_qubits,
ArbCmdQueue &&  cmds 
)
inline

Allocates a number of downstream qubits, copying in the given command queue as arbitrary additional data for the qubits.

Parameters
num_qubitsThe number of qubits to allocate.
cmdsA command queue with zero or more commands to apply to the qubits during their initialization. The significance of these commands is dependent on the downstream plugin.
Returns
A qubit set with references to the newly allocated qubits.
Exceptions
std::runtime_errorWhen the command queue is invalid, construction of the qubit set fails for some reason, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6165 of file dqcsim.

◆ allocate() [2/6]

QubitSet dqcsim::wrap::PluginState::allocate ( size_t  num_qubits,
ArbCmdQueue cmds 
)
inline

Allocates a number of downstream qubits, moving in the given command queue as arbitrary additional data for the qubits.

Parameters
num_qubitsThe number of qubits to allocate.
cmdsA command queue with zero or more commands to apply to the qubits during their initialization. The significance of these commands is dependent on the downstream plugin.
Returns
A qubit set with references to the newly allocated qubits.
Exceptions
std::runtime_errorWhen the command queue is invalid, construction of the qubit set fails for some reason, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6186 of file dqcsim.

◆ allocate() [3/6]

QubitSet dqcsim::wrap::PluginState::allocate ( size_t  num_qubits)
inline

Allocates a number of default downstream qubits.

Parameters
num_qubitsThe number of qubits to allocate.
Returns
A qubit set with references to the newly allocated qubits.
Exceptions
std::runtime_errorWhen construction of the qubit set fails for some reason, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6203 of file dqcsim.

◆ allocate() [4/6]

QubitRef dqcsim::wrap::PluginState::allocate ( ArbCmdQueue &&  cmds)
inline

Allocates a single downstream qubit, copying in the given command queue as arbitrary additional data for the qubits.

Parameters
cmdsA command queue with zero or more commands to apply to the qubit during its initialization. The significance of these commands is dependent on the downstream plugin.
Returns
A reference to the newly allocated qubit.
Exceptions
std::runtime_errorWhen the command queue is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6223 of file dqcsim.

◆ allocate() [5/6]

QubitRef dqcsim::wrap::PluginState::allocate ( ArbCmdQueue cmds)
inline

Allocates a single downstream qubit, moving in the given command queue as arbitrary additional data for the qubits.

Parameters
cmdsA command queue with zero or more commands to apply to the qubit during its initialization. The significance of these commands is dependent on the downstream plugin.
Returns
A reference to the newly allocated qubit.
Exceptions
std::runtime_errorWhen the command queue is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6243 of file dqcsim.

◆ allocate() [6/6]

QubitRef dqcsim::wrap::PluginState::allocate ( )
inline

Allocates a single downstream qubit.

Returns
A reference to the newly allocated qubit.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6258 of file dqcsim.

◆ free() [1/3]

void dqcsim::wrap::PluginState::free ( QubitSet &&  qubits)
inline

Frees the given downstream qubits.

Parameters
qubitsThe list of qubits to free, passed by move.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6274 of file dqcsim.

◆ free() [2/3]

void dqcsim::wrap::PluginState::free ( const QubitSet qubits)
inline

Frees the given downstream qubits.

Parameters
qubitsThe list of qubits to free, passed by copy.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6290 of file dqcsim.

◆ free() [3/3]

void dqcsim::wrap::PluginState::free ( const QubitRef qubit)
inline

Frees the given downstream qubit.

Parameters
qubitThe qubit to free.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6305 of file dqcsim.

◆ gate() [1/4]

void dqcsim::wrap::PluginState::gate ( Gate &&  gate)
inline

Sends a gate to the downstream plugin.

Parameters
gateThe gate to send.
Exceptions
std::runtime_errorWhen the gate handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6321 of file dqcsim.

◆ gate() [2/4]

void dqcsim::wrap::PluginState::gate ( const Matrix matrix,
const QubitRef q 
)
inline

Shorthand for sending a single-qubit gate to the downstream plugin.

Parameters
matrixThe gate matrix. Must be 2x2 in size.
qThe qubit to operate on.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6337 of file dqcsim.

◆ gate() [3/4]

void dqcsim::wrap::PluginState::gate ( const Matrix matrix,
const QubitRef qa,
const QubitRef qb 
)
inline

Shorthand for sending a two-qubit gate to the downstream plugin.

Parameters
matrixThe gate matrix. It may be 2x2 (one-qubit gate) or 4x4 (two-qubit gate) in size. If it is 2x2, qa is used as an implicit control qubit while qb is the target; for instance, gate(X, a, b) represents a CNOT with a as control and b as target.
qaThe first qubit argument.
qbThe second qubit argument.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6361 of file dqcsim.

◆ gate() [4/4]

void dqcsim::wrap::PluginState::gate ( const Matrix matrix,
const QubitRef qa,
const QubitRef qb,
const QubitRef qc 
)
inline

Shorthand for sending a three-qubit gate to the downstream plugin.

The matrix may be 2x2 (one-qubit gate), 4x4 (two-qubit gate), or 8x8 (three-qubit gate) in size. If it is 2x2, qa and qb are used as control qubits and qc is the target. If it is 4x4, qa is used as a control qubit and qb and qc are the targets.

Parameters
matrixThe gate matrix. It may be 2x2 (one-qubit gate), 4x4 (two-qubit gate), or 8x8 (three-qubit gate) in size. If it is 2x2, qa and qb are used as control qubits and qc is the target. If it is 4x4, qa is used as a control qubit and qb and qc are the targets. For instance, gate(X, a, b, c) represents a Toffoli gate with a and b as controls and c as target, and gate(SWAP, a, b, c) represents a Fredkin gate with a as control and b and c as targets.
qaThe first qubit argument.
qbThe second qubit argument.
qcThe third qubit argument.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6397 of file dqcsim.

◆ measure_x() [1/2]

void dqcsim::wrap::PluginState::measure_x ( const QubitRef q)
inline

Shorthand for sending a single-qubit X-axis measurement to the downstream plugin.

This actually sends the following gates to the downstream plugin for each qubit:

{C++}
gate(Matrix(PredefinedGate::H), q);
gate(Matrix(PredefinedGate::H), q);
Parameters
qThe qubit to measure.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6430 of file dqcsim.

◆ measure_x() [2/2]

void dqcsim::wrap::PluginState::measure_x ( const QubitSet qs)
inline

Shorthand for sending a multi-qubit X-axis measurement to the downstream plugin.

This actually sends the following gates to the downstream plugin for each qubit:

{C++}
for (q : qs) gate(Matrix(PredefinedGate::H), q);
for (q : qs) gate(Matrix(PredefinedGate::H), q);
Parameters
qsThe qubits to measure.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6458 of file dqcsim.

◆ measure_y() [1/2]

void dqcsim::wrap::PluginState::measure_y ( const QubitRef q)
inline

Shorthand for sending a single-qubit Y-axis measurement to the downstream plugin.

This actually sends the following gates to the downstream plugin for each qubit:

{C++}
gate(Matrix(PredefinedGate::S), q);
gate(Matrix(PredefinedGate::Z), q);
gate(Matrix(PredefinedGate::S), q);
Parameters
qThe qubit to measure.
Exceptions
std::runtime_errorWhen an asynchronous exception is received or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6487 of file dqcsim.

◆ measure_y() [2/2]

void dqcsim::wrap::PluginState::measure_y ( const QubitSet qs)
inline

Shorthand for sending a multi-qubit Y-axis measurement to the downstream plugin.

This actually sends the following gates to the downstream plugin for each qubit:

{C++}
for (q : qs) gate(Matrix(PredefinedGate::S), q);
for (q : qs) gate(Matrix(PredefinedGate::Z), q);
for (q : qs) gate(Matrix(PredefinedGate::S), q);
Parameters
qsThe qubits to measure.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6517 of file dqcsim.

◆ measure_z() [1/3]

void dqcsim::wrap::PluginState::measure_z ( const QubitRef q)
inline

Shorthand for sending a single-qubit Z-axis measurement to the downstream plugin.

Parameters
qThe qubit to measure.
Exceptions
std::runtime_errorWhen an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6537 of file dqcsim.

◆ measure_z() [2/3]

void dqcsim::wrap::PluginState::measure_z ( QubitSet &&  qs)
inline

Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.

Parameters
qsThe qubits to measure.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6554 of file dqcsim.

◆ measure_z() [3/3]

void dqcsim::wrap::PluginState::measure_z ( const QubitSet qs)
inline

Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.

Parameters
qsThe qubits to measure.
Exceptions
std::runtime_errorWhen the qubit set handle is invalid, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6571 of file dqcsim.

◆ advance()

Cycle dqcsim::wrap::PluginState::advance ( Cycle  cycles)
inline

Tells the downstream plugin to run for the specified number of cycles.

Parameters
cyclesThe number of cycles to advance by. Must be positive.
Returns
The return value is the new cycle counter.
Exceptions
std::runtime_errorWhen number of cycles is negative, an asynchronous exception is received, or this is called by a backend plugin.
Note
This function is implemented asynchronously for multiprocessing performance reasons. Therefore, any exception thrown by the downstream plugin will not be (immediately) visible.

Definition at line 6587 of file dqcsim.

◆ arb() [1/2]

ArbData dqcsim::wrap::PluginState::arb ( ArbCmd &&  cmd)
inline

Sends an arbitrary command downstream.

Parameters
cmdThe command to send to the downstream plugin.
Returns
The ArbData object returned by the downstream plugin.
Exceptions
std::runtime_errorWhen the command fails, an asynchronous exception is received, or this is called by a backend plugin.

Definition at line 6599 of file dqcsim.

◆ arb() [2/2]

ArbData dqcsim::wrap::PluginState::arb ( const ArbCmd cmd)
inline

Sends an arbitrary command downstream.

Parameters
cmdThe command to send to the downstream plugin.
Returns
The ArbData object returned by the downstream plugin.
Exceptions
std::runtime_errorWhen the command fails, an asynchronous exception is received, or this is called by a backend plugin.

Definition at line 6611 of file dqcsim.

◆ get_measurement()

Measurement dqcsim::wrap::PluginState::get_measurement ( const QubitRef qubit)
inline

Returns the latest measurement of the given downstream qubit.

Parameters
qubitThe qubit to return the latest measurement for.
Returns
The latest measurement result.
Exceptions
std::runtime_errorWhen no data is known for the given qubit, measurement object construction fails, or this is called by a backend plugin.

Definition at line 6624 of file dqcsim.

◆ get_cycles_since_measure()

Cycle dqcsim::wrap::PluginState::get_cycles_since_measure ( const QubitRef qubit)
inline

Returns the number of downstream cycles since the latest measurement of the given downstream qubit.

Parameters
qubitThe qubit to return the cycle count for.
Returns
The number of downstream cycles since the latest measurement.
Exceptions
std::runtime_errorWhen no data is known for the given qubit or this is called by a backend plugin.

Definition at line 6637 of file dqcsim.

◆ get_cycles_between_measures()

Cycle dqcsim::wrap::PluginState::get_cycles_between_measures ( const QubitRef qubit)
inline

Returns the number of downstream cycles between the last two measurements of the given downstream qubit.

Parameters
qubitThe qubit to return the cycle count for.
Returns
The number of downstream cycles between the previous measurement and the one before.
Exceptions
std::runtime_errorWhen no data is known for the given qubit or this is called by a backend plugin.

Definition at line 6651 of file dqcsim.

◆ get_cycle()

Cycle dqcsim::wrap::PluginState::get_cycle ( )
inline

Returns the current value of the downstream cycle counter.

Returns
The number downstream simulation cycle counter value.
Exceptions
std::runtime_errorWhen this is called by a backend plugin.

Definition at line 6661 of file dqcsim.


The documentation for this class was generated from the following file:
dqcsim::wrap::PluginState::measure_z
void measure_z(const QubitRef &q)
Shorthand for sending a single-qubit Z-axis measurement to the downstream plugin.
Definition: dqcsim:6537
dqcsim::wrap::PluginState::gate
void gate(Gate &&gate)
Sends a gate to the downstream plugin.
Definition: dqcsim:6321
dqcsim::wrap::PluginState::measure_x
void measure_x(const QubitRef &q)
Shorthand for sending a single-qubit X-axis measurement to the downstream plugin.
Definition: dqcsim:6430