DQCsim
|
Gate map wrapper class. More...
Public Member Functions | |
GateMap (HandleIndex handle) noexcept | |
Wraps the given gate map handle. More... | |
GateMap (bool strip_qubit_refs=false, bool strip_data=false) | |
Constructs a new gate map. More... | |
GateMap (const GateMap &)=delete | |
void | operator= (const GateMap &)=delete |
GateMap (GateMap &&)=default | |
Default move constructor. | |
GateMap & | operator= (GateMap &&)=default |
Default move assignment. | |
GateMap && | with_unitary (Unbound &&key, PredefinedGate gate, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true) |
Adds a unitary gate mapping for the given DQCsim-defined gate. More... | |
GateMap && | with_unitary (const Unbound &key, PredefinedGate gate, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true) |
Adds a unitary gate mapping for the given DQCsim-defined gate. More... | |
GateMap && | with_unitary (Unbound &&key, Matrix &&matrix, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true) |
Adds a unitary gate mapping for the given unitary matrix. More... | |
GateMap && | with_unitary (const Unbound &key, const Matrix &matrix, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true) |
Adds a unitary gate mapping for the given unitary matrix. More... | |
GateMap && | with_unitary (Unbound &&key, const std::shared_ptr< CustomUnitaryGateConverter > &converter) |
Adds a custom unitary gate mapping. More... | |
GateMap && | with_unitary (const Unbound &key, const std::shared_ptr< CustomUnitaryGateConverter > &converter) |
Adds a custom unitary gate mapping. More... | |
GateMap && | with_measure (Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1) |
Adds a measurement gate mapping. More... | |
GateMap && | with_measure (const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1) |
Adds a measurement gate mapping. More... | |
GateMap && | with_measure (Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_measures=-1) |
Adds a measurement gate mapping. More... | |
GateMap && | with_measure (const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_measures=-1) |
Adds a measurement gate mapping. More... | |
GateMap && | with_prep (Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1) |
Adds a prep gate mapping. More... | |
GateMap && | with_prep (const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1) |
Adds a prep gate mapping. More... | |
GateMap && | with_prep (Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_targets=-1) |
Adds a prep gate mapping. More... | |
GateMap && | with_prep (const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_targets=-1) |
Adds a prep gate mapping. More... | |
GateMap && | with_custom (Unbound &&key, const std::shared_ptr< CustomGateConverter > &converter) |
Adds a custom gate mapping. More... | |
GateMap && | with_custom (const Unbound &key, const std::shared_ptr< CustomGateConverter > &converter) |
Adds a custom gate mapping. More... | |
bool | detect (const Gate &gate, const Unbound **unbound, QubitSet *qubits, ArbData *params) |
Uses the gate map to convert an incoming DQCsim gate to the plugin's Unbound representation. More... | |
Gate | construct (const Unbound &unbound, QubitSet &&qubits, ArbData &¶ms) |
Uses a gate map object to construct a DQCsim gate from the plugin's representation. More... | |
Gate | construct (const Unbound &unbound, const QubitSet &qubits, const ArbData ¶ms) |
Uses a gate map object to construct a DQCsim gate from the plugin's representation. More... | |
Gate | construct (const Unbound &unbound, QubitSet &&qubits) |
Uses a gate map object to construct a DQCsim gate from the plugin's representation. More... | |
Gate | construct (const Unbound &unbound, const QubitSet &qubits) |
Uses a gate map object to construct a DQCsim gate from the plugin's representation. More... | |
Bound | convert (const Gate &gate) |
Wrapper function for detect() , converting from DQCsim's gate representation directly to the plugin's Bound gate type. More... | |
Gate | convert (const Bound &bound) |
Wrapper function for construct() , converting directly from the plugin's Bound gate type to DQCsim's gate representation. More... | |
Public Member Functions inherited from dqcsim::wrap::Handle | |
Handle () noexcept | |
Constructs an empty wrapper. More... | |
Handle (HandleIndex handle) noexcept | |
Wraps the given raw handle. More... | |
virtual | ~Handle () noexcept |
Delete the handle and its wrapper. | |
void | free () |
Explicitly delete the handle, allowing errors to be caught. More... | |
bool | is_valid () const noexcept |
Returns whether this wrapper (still) contains a valid handle. More... | |
HandleIndex | get_handle () const noexcept |
Returns the raw handle without relinquishing ownership. More... | |
HandleIndex | take_handle () noexcept |
Returns the raw handle and relinquishes ownership. More... | |
Handle (const Handle &)=delete | |
void | operator= (const Handle &)=delete |
Handle (Handle &&src) | |
Move constructor; simply moves ownership of the handle from the source object to the constructed object. More... | |
Handle & | operator= (Handle &&src) |
Move constructor; simply moves ownership of the handle from the source object to the assignment target. More... | |
std::string | dump () const |
Returns a string containing a debug dump of the handle. More... | |
HandleType | type () const |
Returns the type of this handle. More... | |
Additional Inherited Members | |
Protected Attributes inherited from dqcsim::wrap::Handle | |
HandleIndex | handle |
The wrapped handle. | |
Gate map wrapper class.
Gate maps are used to convert between DQCsim's gate representation and your own, given that your representation consists of the following:
Unbound
type representing a kind of gate with some amount of quantum and/or classical arguments that have not been bound yet;QubitSet
;ArbData
.The template expects that the Unbound
and Bound
types define the following methods:
Unbound
must define a move or copy constructor.Unbound::operator==
must be implemented properly.std::hash<Unbound>
must be implemented properly.Bound Unbound::bind(QubitSet &&qubits, ArbData &¶ms) const
is implemented, you can use the Bound convert(Gate &&gate)
method. This is just a shorthand for detect()
, which you can always use.Unbound Bound::get_unbound() const
, QubitSet Bound::get_qubits() const
, and ArbData Bound::get_params() const
are implemented, you can use the Gate convert(Bound &&bound)
method. This is just a shorthand for construct()
, which you can always use.Note that the Unbound
and Bound
types can be one and the same, and by default are.
DQCsim provides a number of predefined converters to detect and construct commonly used gates, but for more complex gates you'll of course have to define your own conversion functions.
For more information, refer to the C API documentation.
|
inlinenoexcept |
|
inline |
Constructs a new gate map.
Gate maps objects retain a cache to speed up detection of similar DQCsim gates: if a gate is received for the second time, the cache will hit, avoiding recomputation of the detector functions. What constitutes "similar gates" is defined by the two booleans passed to this function.
strip_qubit_refs | If set, all qubit references associated with the gate will be invalidated (i.e., set to 0), such that for instance an X gate applied to qubit 1 will be considered equal to an X gate applied to qubit 2. |
strip_data | If set, the ArbData associated with the incoming gate is removed. |
std::runtime_error | When construction of the gate map fails. |
Unbound
type is hashable with std::hash
and has a defined equality operator.
|
inline |
Adds a unitary gate mapping for the given DQCsim-defined gate.
key | The Unbound object that refers to this type of gate in your representation. |
gate | The predefined DQCsim gate to detect. |
num_controls | The number of control qubits for this type of gate. If negative, the gate can be controlled with any number of qubits or not controlled; disambiguation is done based on the number of qubit arguments. If zero, the gate is always non-controlled. If positive, the gate always has the specified number of control qubits. |
epsilon | The maximum RMS error used when detecting incoming gate matrices. Defaults to 1 ppm. |
ignore_global_phase | Whether global phase should be ignored when detecting incoming gate matrices. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a unitary gate mapping for the given DQCsim-defined gate.
key | The Unbound object that refers to this type of gate in your representation. |
gate | The predefined DQCsim gate to detect. |
num_controls | The number of control qubits for this type of gate. If negative, the gate can be controlled with any number of qubits or not controlled; disambiguation is done based on the number of qubit arguments. If zero, the gate is always non-controlled. If positive, the gate always has the specified number of control qubits. |
epsilon | The maximum RMS error used when detecting incoming gate matrices. Defaults to 1 ppm. |
ignore_global_phase | Whether global phase should be ignored when detecting incoming gate matrices. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Adds a unitary gate mapping for the given unitary matrix.
key | The Unbound object that refers to this type of gate in your representation. |
matrix | The matrix to detect. |
num_controls | The number of control qubits for this type of gate. If negative, the gate can be controlled with any number of qubits or not controlled; disambiguation is done based on the number of qubit arguments. If zero, the gate is always non-controlled. If positive, the gate always has the specified number of control qubits. |
epsilon | The maximum RMS error used when detecting incoming gate matrices. Defaults to 1 ppm. |
ignore_global_phase | Whether global phase should be ignored when detecting incoming gate matrices. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a unitary gate mapping for the given unitary matrix.
key | The Unbound object that refers to this type of gate in your representation. |
matrix | The matrix to detect. |
num_controls | The number of control qubits for this type of gate. If negative, the gate can be controlled with any number of qubits or not controlled; disambiguation is done based on the number of qubit arguments. If zero, the gate is always non-controlled. If positive, the gate always has the specified number of control qubits. |
epsilon | The maximum RMS error used when detecting incoming gate matrices. Defaults to 1 ppm. |
ignore_global_phase | Whether global phase should be ignored when detecting incoming gate matrices. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Adds a custom unitary gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
converter | An object deriving from CustomUnitaryGateConverter , implemented by you to handle the conversion, wrapped in a std::shared_ptr . |
std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a custom unitary gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
converter | An object deriving from CustomUnitaryGateConverter , implemented by you to handle the conversion. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Adds a measurement gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The measurement basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_measures | The number of measurement qubits for this type of gate. If negative, the gate can measure any number of qubits at a time. If positive, the gate always has the specified number of measurement qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a measurement gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The measurement basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_measures | The number of measurement qubits for this type of gate. If negative, the gate can measure any number of qubits at a time. If positive, the gate always has the specified number of measurement qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Adds a measurement gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The measurement basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_measures | The number of measurement qubits for this type of gate. If negative, the gate can measure any number of qubits at a time. If positive, the gate always has the specified number of measurement qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a measurement gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The measurement basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_measures | The number of measurement qubits for this type of gate. If negative, the gate can measure any number of qubits at a time. If positive, the gate always has the specified number of measurement qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Adds a prep gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_targets | The number of target qubits for this type of gate. If negative, the gate can prepare any number of qubits at a time. If positive, the gate always has the specified number of target qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a prep gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_targets | The number of target qubits for this type of gate. If negative, the gate can prepare any number of qubits at a time. If positive, the gate always has the specified number of target qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a prep gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_targets | The number of target qubits for this type of gate. If negative, the gate can prepare any number of qubits at a time. If positive, the gate always has the specified number of target qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a prep gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
basis | The basis. |
epsilon | Maximum RMS deviation when detecting the above basis. |
num_targets | The number of target qubits for this type of gate. If negative, the gate can prepare any number of qubits at a time. If positive, the gate always has the specified number of target qubits. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a custom gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
converter | An object deriving from CustomGateConverter , implemented by you to handle the conversion, wrapped in a std::shared_ptr . |
std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a move constructor.
|
inline |
Adds a custom gate mapping.
key | The Unbound object that refers to this type of gate in your representation. |
converter | An object deriving from CustomGateConverter , implemented by you to handle the conversion. |
&self
, to continue building. std::runtime_error | When the gate map handle is invalid. |
Unbound
type has a copy constructor.
|
inline |
Uses the gate map to convert an incoming DQCsim gate to the plugin's Unbound
representation.
gate | The gate to detect. |
unbound | If non-null and the incoming gate matches one of the detectors, this receives a const pointer to the internal Unbound record corresponding with the first detector that matched. If there is no match, this is left unchanged, allowing a default value to be supplied. |
qubits | If non-null and the incoming gate matches one of the detectors, the given QubitSet is set to the qubit arguments for the matched gate. |
params | If non-null and the incoming gate matches one of the detectors, the given ArbData is set to the parameterization data object returned by the detector function. |
std::runtime_error | When one of the handles is invalid or one of the detector functions returned an error. |
|
inline |
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
unbound | The plugin's representation of the unbound gate. |
qubits | The qubit arguments for the gate. |
params | The parameterization data for the gate. |
std::runtime_error | When unbound does not map to any converter function, the converter function returns an error, or one of the involved handles is invalid. |
|
inline |
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
unbound | The plugin's representation of the unbound gate. |
qubits | The qubit arguments for the gate. |
params | The parameterization data for the gate. |
std::runtime_error | When unbound does not map to any converter function, the converter function returns an error, or one of the involved handles is invalid. |
|
inline |
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
unbound | The plugin's representation of the unbound gate. |
qubits | The qubit arguments for the gate. |
std::runtime_error | When unbound does not map to any converter function, the converter function returns an error, or one of the involved handles is invalid. |
|
inline |
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
unbound | The plugin's representation of the unbound gate. |
qubits | The qubit arguments for the gate. |
std::runtime_error | When unbound does not map to any converter function, the converter function returns an error, or one of the involved handles is invalid. |
|
inline |
Wrapper function for detect()
, converting from DQCsim's gate representation directly to the plugin's Bound
gate type.
gate | The gate to convert. |
std::runtime_error | When the DQCsim gate cannot be represented in the plugin's representation, one of the handles is invalid, or one of the detector functions returned an error. |
Bound Unbound::bind(QubitSet &&qubits, ArbData &¶ms) const
exists. This method is used to convert from the return values of detect()
to an instance of Bound
.
|
inline |
Wrapper function for construct()
, converting directly from the plugin's Bound
gate type to DQCsim's gate representation.
bound | The plugin's gate representation. |
std::runtime_error | When bound does not map to any converter function, the converter function returns an error, or one of the involved handles is invalid. |
Unbound Bound::get_unbound() const
, QubitSet Bound::get_qubits() const
, and ArbData Bound::get_params() const
are implemented. These methods are used to convert from the Bound
gate to the inputs of construct()
.