Quantum++
v1.2
A modern C++11 quantum computing library
|
Quantum circuit class. More...
#include <classes/circuits.h>
Classes | |
struct | GateStep |
One step consisting only of gates/operators in the circuit. More... | |
class | iterator |
Quantum circuit bound-checking (safe) iterator. More... | |
struct | MeasureStep |
One step consisting only of measurements in the circuit. More... | |
Public Types | |
enum | GateType { GateType::NONE, GateType::SINGLE, GateType::TWO, GateType::THREE, GateType::CUSTOM, GateType::FAN, GateType::QFT, GateType::TFQ, GateType::SINGLE_CTRL_SINGLE_TARGET, GateType::SINGLE_CTRL_MULTIPLE_TARGET, GateType::MULTIPLE_CTRL_SINGLE_TARGET, GateType::MULTIPLE_CTRL_MULTIPLE_TARGET, GateType::CUSTOM_CTRL, GateType::SINGLE_cCTRL_SINGLE_TARGET, GateType::SINGLE_cCTRL_MULTIPLE_TARGET, GateType::MULTIPLE_cCTRL_SINGLE_TARGET, GateType::MULTIPLE_cCTRL_MULTIPLE_TARGET, GateType::CUSTOM_cCTRL } |
Type of gate being executed in a gate step. More... | |
enum | MeasureType { MeasureType::NONE, MeasureType::MEASURE_Z, MeasureType::MEASURE_V, MeasureType::MEASURE_V_MANY } |
Type of measurement being executed in a measurement step. More... | |
enum | StepType { StepType::NONE, StepType::GATE, StepType::MEASUREMENT } |
Types of each step in the quantum circuit. More... | |
using | const_iterator = iterator |
both iterators are const_iterators More... | |
Public Member Functions | |
iterator | begin () |
Iterator to the first element. More... | |
const_iterator | begin () const noexcept |
Constant iterator to the first element. More... | |
const_iterator | cbegin () const noexcept |
Constant iterator to the first element. More... | |
iterator | end () |
Iterator to the next to the last element. More... | |
const_iterator | end () const noexcept |
Constant iterator to the next to the last element. More... | |
const_iterator | cend () const noexcept |
Constant iterator to the next to the last element. More... | |
QCircuit (idx nq, idx nc=0, idx d=2, std::string name="") | |
Constructs a quantum circuit. More... | |
virtual | ~QCircuit ()=default |
Default virtual destructor. More... | |
idx | get_nq () const noexcept |
Total number of qudits in the circuit. More... | |
idx | get_nc () const noexcept |
Total number of classical dits in the circuit. More... | |
idx | get_d () const noexcept |
Dimension of the comprising qudits. More... | |
std::string | get_name () const |
Quantum circuit name. More... | |
idx | get_measured (idx i) const |
Check whether qudit i was already measured. More... | |
std::vector< idx > | get_measured () const |
Vector of already measured qudit indexes. More... | |
std::vector< idx > | get_non_measured () const |
Vector of non-measured qudit indexes. More... | |
idx | get_gate_count () const noexcept |
Quantum circuit total gate count. More... | |
idx | get_gate_count (const std::string &name) const |
Quantum circuit gate count. More... | |
idx | get_gate_depth () const |
Quantum circuit total gate depth. More... | |
idx | get_gate_depth (const std::string &name QPP_UNUSED_) const |
Quantum circuit gate depth. More... | |
idx | get_measurement_count () const noexcept |
Quantum circuit total measurement count. More... | |
idx | get_measurement_count (const std::string &name) const |
Quantum circuit measurement count. More... | |
idx | get_step_count () const noexcept |
Quantum circuit total steps count, i.e. the sum of gate count and measurement count. More... | |
QCircuit & | gate (const cmat &U, idx i, std::string name="") |
Applies the single qudit gate U on single qudit i. More... | |
QCircuit & | gate (const cmat &U, idx i, idx j, std::string name="") |
Applies the two qudit gate U on qudits i and j. More... | |
QCircuit & | gate (const cmat &U, idx i, idx j, idx k, std::string name="") |
Applies the three qudit gate U on qudits i, j and k. More... | |
QCircuit & | gate_fan (const cmat &U, const std::vector< idx > &target, std::string name="") |
Applies the single qudit gate U on every qudit listed in target. More... | |
QCircuit & | gate_fan (const cmat &U, const std::initializer_list< idx > &target, std::string name="") |
Applies the single qudit gate U on every qudit listed in target. More... | |
QCircuit & | gate_fan (const cmat &U, std::string name="") |
Applies the single qudit gate U on every remaining non-measured qudit. More... | |
QCircuit & | gate_custom (const cmat &U, const std::vector< idx > &target, std::string name="") |
Jointly applies the custom multiple qudit gate U on the qudit indexes specified by target. More... | |
QCircuit & | QFT (const std::vector< idx > &target, bool swap QPP_UNUSED_=true) |
Applies the quantum Fourier transform (as a series of gates) on the qudit indexes specified by target. More... | |
QCircuit & | TFQ (const std::vector< idx > &target, bool swap QPP_UNUSED_=true) |
Applies the inverse quantum Fourier transform (as a series of gates) on the qudit indexes specified by target. More... | |
QCircuit & | CTRL (const cmat &U, idx ctrl, idx target, std::string name="") |
Applies the single qudit controlled gate U with control qudit ctrl and target qudit target. More... | |
QCircuit & | CTRL (const cmat &U, idx ctrl, const std::vector< idx > &target, std::string name="") |
Applies the single qudit controlled gate U with control qudit ctrl on every qudit listed in target. More... | |
QCircuit & | CTRL (const cmat &U, const std::vector< idx > &ctrl, idx target, std::string name="") |
Applies the single qudit controlled gate U with multiple control qudits listed in ctrl on the target qudit target. More... | |
QCircuit & | CTRL (const cmat &U, const std::vector< idx > &ctrl, const std::vector< idx > &target, std::string name="") |
Applies the single qudit controlled gate U with multiple control qudits listed in ctrl on every qudit listed in target. More... | |
QCircuit & | CTRL_custom (const cmat &U, const std::vector< idx > &ctrl, const std::vector< idx > &target, std::string name="") |
Jointly applies the custom multiple-qudit controlled gate U with multiple control qudits listed in ctrl on the qudit indexes specified by target. More... | |
QCircuit & | cCTRL (const cmat &U, idx ctrl_dit, idx target, std::string name="") |
Applies the single qubit controlled gate U with classical control dit ctrl and target qudit target. More... | |
QCircuit & | cCTRL (const cmat &U, idx ctrl_dit, const std::vector< idx > &target, std::string name="") |
Applies the single qudit controlled gate U with classical control dit ctrl on every qudit listed in target. More... | |
QCircuit & | cCTRL (const cmat &U, const std::vector< idx > &ctrl_dits, idx target, std::string name="") |
Applies the single qudit controlled gate U with multiple classical control dits listed in ctrl on the target qudit target. More... | |
QCircuit & | cCTRL (const cmat &U, const std::vector< idx > &ctrl_dits, const std::vector< idx > &target, std::string name="") |
Applies the single qudit controlled gate U with multiple classical control dits listed in ctrl on every qudit listed in target. More... | |
QCircuit & | cCTRL_custom (const cmat &U, const std::vector< idx > &ctrl_dits, const std::vector< idx > &target, std::string name="") |
Jointly applies the custom multiple-qudit controlled gate U with multiple classical control dits listed in ctrl on the qudit indexes specified by target. More... | |
QCircuit & | measureZ (idx target, idx c_reg, std::string name="") |
Measurement of single qudit in the computational basis (Z-basis) More... | |
QCircuit & | measureV (const cmat &V, idx target, idx c_reg, std::string name="") |
Measurement of single qudit in the orthonormal basis or rank-1 projectors specified by the columns of matrix V. More... | |
QCircuit & | measureV (const cmat &V, const std::vector< idx > &target, idx c_reg, std::string name="") |
Joint measurement of multiple qudits in the orthonormal basis or rank-1 projectors specified by the columns of matrix V. More... | |
std::string | to_JSON (bool enclosed_in_curly_brackets=true) const override |
qpp::IJOSN::to_JSON() override More... | |
![]() | |
IDisplay ()=default | |
Default constructor. More... | |
IDisplay (const IDisplay &)=default | |
Default copy constructor. More... | |
IDisplay (IDisplay &&)=default | |
Default move constructor. More... | |
IDisplay & | operator= (const IDisplay &)=default |
Default copy assignment operator. More... | |
IDisplay & | operator= (IDisplay &&)=default |
Default move assignment operator. More... | |
virtual | ~IDisplay ()=default |
Default virtual destructor. More... | |
![]() | |
IJSON ()=default | |
Default constructor. More... | |
IJSON (const IJSON &)=default | |
Default copy constructor. More... | |
IJSON (IJSON &&)=default | |
Default move constructor. More... | |
IJSON & | operator= (const IJSON &)=default |
Default copy assignment operator. More... | |
IJSON & | operator= (IJSON &&)=default |
Default move assignment operator. More... | |
virtual | ~IJSON ()=default |
Default virtual destructor. More... | |
Private Member Functions | |
void | add_hash_ (const cmat &U, std::size_t hashU) |
Adds matrix to the hash table. More... | |
const std::vector< MeasureStep > & | get_measurements_ () const noexcept |
Vector of qpp::QCircuit::MeasureStep. More... | |
const std::vector< GateStep > & | get_gates_ () const noexcept |
Vector of qpp::QCircuit::GateStep. More... | |
const std::unordered_map< std::size_t, cmat > & | get_cmat_hash_tbl_ () const noexcept |
Hash table with the matrices used in the circuit. More... | |
std::ostream & | display (std::ostream &os) const override |
qpp::IDisplay::display() override More... | |
Private Attributes | |
const idx | nq_ |
number of qudits More... | |
const idx | nc_ |
number of classical "dits" More... | |
const idx | d_ |
qudit dimension More... | |
std::string | name_ |
optional circuit name More... | |
std::vector< bool > | measured_ |
keeps track of the measured qudits More... | |
std::unordered_map< std::size_t, cmat > | cmat_hash_tbl_ {} |
std::unordered_map< std::string, idx > | count_ {} |
keeps track of the gate counts More... | |
std::unordered_map< std::string, idx > | depth_ {} |
keeps track of the gate depths More... | |
std::unordered_map< std::string, idx > | measurement_count_ {} |
keeps track of the measurement counts More... | |
std::vector< GateStep > | gates_ {} |
gates More... | |
std::vector< MeasureStep > | measurements_ {} |
measurements More... | |
std::vector< StepType > | step_types_ {} |
type of each step More... | |
Friends | |
class | QEngine |
std::ostream & | operator<< (std::ostream &os, const GateType &gate_type) |
Extraction operator overload for qpp::QCircuit::GateType enum class. More... | |
std::ostream & | operator<< (std::ostream &os, const GateStep &gate_step) |
Extraction operator overload for qpp::QCircuit::GateStep class. More... | |
std::ostream & | operator<< (std::ostream &os, const MeasureType &measure_type) |
Extraction operator overload for qpp::QCircuit::MeasureType enum class. More... | |
std::ostream & | operator<< (std::ostream &os, const MeasureStep &measure_step) |
Extraction operator overload for qpp::QCircuit::MeasureStep class. More... | |
Quantum circuit class.
both iterators are const_iterators
|
strong |
Type of gate being executed in a gate step.
|
strong |
Type of measurement being executed in a measurement step.
|
strong |
Constructs a quantum circuit.
nq | Number of qbits |
nc | Number of classical dits |
d | Subsystem dimensions (optional, default is qubit, i.e. d = 2) |
name | Circuit name (optional) |
|
virtualdefault |
Default virtual destructor.
|
inlineprivate |
Adds matrix to the hash table.
U | Complex matrix |
hashU | Hash value of U |
|
inline |
Iterator to the first element.
|
inlinenoexcept |
Constant iterator to the first element.
|
inlinenoexcept |
Constant iterator to the first element.
|
inline |
Applies the single qubit controlled gate U with classical control dit ctrl and target qudit target.
U | Single qudit quantum gate |
ctrl_dit | Classical control dit index |
target | Target qudit index |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with classical control dit ctrl on every qudit listed in target.
U | Single qudit quantum gate |
ctrl_dit | Classical control dit index |
target | Target qudit indexes; the gate U is applied on every one of them depending on the values of the classical control dits |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with multiple classical control dits listed in ctrl on the target qudit target.
U | Single qudit quantum gate |
ctrl_dits | Classical control dits indexes |
target | Target qudit index |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with multiple classical control dits listed in ctrl on every qudit listed in target.
U | Single qudit quantum gate |
ctrl_dits | Classical control dits indexes |
target | Target qudit indexes; the gate U is applied on every one of them depending on the values of the classical control dits |
name | Optional gate name |
|
inline |
Jointly applies the custom multiple-qudit controlled gate U with multiple classical control dits listed in ctrl on the qudit indexes specified by target.
U | Multiple-qudit quantum gate |
ctrl_dits | Classical control dits indexes |
target | Target qudit indexes where the gate U is applied depending on the values of the classical control dits |
name | Optional gate name |
|
inlinenoexcept |
Constant iterator to the next to the last element.
|
inline |
Applies the single qudit controlled gate U with control qudit ctrl and target qudit target.
U | Single qudit quantum gate |
ctrl | Control qudit index |
target | Target qudit index |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with control qudit ctrl on every qudit listed in target.
U | Single qudit quantum gate |
ctrl | Control qudit index |
target | Target qudit indexes; the gate U is applied on every one of them depending on the values of the control qudits |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with multiple control qudits listed in ctrl on the target qudit target.
U | Single qudit quantum gate |
ctrl | Control qudit indexes |
target | Target qudit index |
name | Optional gate name |
|
inline |
Applies the single qudit controlled gate U with multiple control qudits listed in ctrl on every qudit listed in target.
U | Single qudit quantum gate |
ctrl | Control qudit indexes |
target | Target qudit indexes; the gate U is applied on every one of them depending on the values of the control qudits |
name | Optional gate name |
|
inline |
Jointly applies the custom multiple-qudit controlled gate U with multiple control qudits listed in ctrl on the qudit indexes specified by target.
U | Multiple-qudit quantum gate |
ctrl | Control qudit indexes |
target | Target qudit indexes where the gate U is applied depending on the values of the control qudits |
name | Optional gate name |
|
inlineoverrideprivatevirtual |
qpp::IDisplay::display() override
Writes to the output stream a textual representation of the quantum circuit
os | Output stream passed by reference |
Implements qpp::IDisplay.
|
inline |
Iterator to the next to the last element.
|
inlinenoexcept |
Constant iterator to the next to the last element.
Applies the single qudit gate U on single qudit i.
U | Single qudit quantum gate |
i | Qudit index |
name | Optional gate name |
Applies the two qudit gate U on qudits i and j.
U | Two qudit quantum gate |
i | Qudit index |
j | Qudit index |
name | Optional gate name |
Applies the three qudit gate U on qudits i, j and k.
U | Three qudit quantum gate |
i | Qudit index |
j | Qudit index |
k | Qudit index |
name | Optional gate name |
|
inline |
Jointly applies the custom multiple qudit gate U on the qudit indexes specified by target.
U | Multiple qudit quantum gate |
target | Subsystem indexes where the gate U is applied |
name | Optional gate name |
|
inline |
Applies the single qudit gate U on every qudit listed in target.
U | Single qudit quantum gate |
target | Target qudit indexes; the gate U is applied on every one of them |
name | Optional gate name |
|
inline |
Applies the single qudit gate U on every qudit listed in target.
U | Single qudit quantum gate |
target | Target qudit indexes; the gate U is applied on every one of them |
name | Optional gate name |
Applies the single qudit gate U on every remaining non-measured qudit.
U | Single qudit quantum gate |
name | Optional gate name |
|
inlineprivatenoexcept |
Hash table with the matrices used in the circuit.
|
inlinenoexcept |
Dimension of the comprising qudits.
|
inlinenoexcept |
Quantum circuit total gate count.
|
inline |
Quantum circuit gate count.
name | Gate name |
|
inline |
Quantum circuit total gate depth.
|
inline |
Quantum circuit gate depth.
name | Gate name |
|
inlineprivatenoexcept |
Vector of qpp::QCircuit::GateStep.
Check whether qudit i was already measured.
i | Qudit index |
|
inline |
Vector of already measured qudit indexes.
|
inlinenoexcept |
Quantum circuit total measurement count.
|
inline |
Quantum circuit measurement count.
name | Measurement name |
|
inlineprivatenoexcept |
Vector of qpp::QCircuit::MeasureStep.
|
inline |
Quantum circuit name.
|
inlinenoexcept |
Total number of classical dits in the circuit.
|
inline |
Vector of non-measured qudit indexes.
|
inlinenoexcept |
Total number of qudits in the circuit.
|
inlinenoexcept |
Quantum circuit total steps count, i.e. the sum of gate count and measurement count.
|
inline |
Measurement of single qudit in the orthonormal basis or rank-1 projectors specified by the columns of matrix V.
V | Orthonormal basis or rank-1 projectors specified by the columns of matrix V |
target | Qudit index |
c_reg | Classical register where the value of the measurement is stored |
name | Optional measurement name |
|
inline |
Joint measurement of multiple qudits in the orthonormal basis or rank-1 projectors specified by the columns of matrix V.
V | Orthonormal basis or rank-1 projectors specified by the columns of matrix V |
target | Target qudit indexes that are jointly measured |
c_reg | Classical register where the value of the measurement is stored |
name | Optional measurement name |
Measurement of single qudit in the computational basis (Z-basis)
target | Qudit index |
c_reg | Classical register where the value of the measurement is being stored |
name | Optional measurement name, default is "Measure Z" |
|
inline |
Applies the quantum Fourier transform (as a series of gates) on the qudit indexes specified by target.
target | Subsystem indexes where the quantum Fourier transform is applied |
swap | Swaps the qubits at the end (true by default) |
|
inline |
Applies the inverse quantum Fourier transform (as a series of gates) on the qudit indexes specified by target.
target | Subsystem indexes where the inverse quantum Fourier transform is applied |
swap | Swaps the qubits at the end (true by default) |
|
inlineoverridevirtual |
qpp::IJOSN::to_JSON() override
Displays the quantum circuit in JSON format
enclosed_in_curly_brackets | If true, encloses the result in curly brackets |
Implements qpp::IJSON.
|
friend |
Extraction operator overload for qpp::QCircuit::GateType enum class.
os | Output stream |
gate_type | qpp::QCircuit::GateType enum class |
|
friend |
Extraction operator overload for qpp::QCircuit::GateStep class.
os | Output stream |
gate_type | qpp::QCircuit::GateStep class |
|
friend |
Extraction operator overload for qpp::QCircuit::MeasureType enum class.
os | Output stream |
gate_type | qpp::QCircuit::MeasureType enum class |
|
friend |
Extraction operator overload for qpp::QCircuit::MeasureStep class.
os | Output stream |
gate_type | qpp::QCircuit::MeasureStep enum class |
|
friend |
|
private |
hash table with the matrices used in the circuit, with [Key = idx, Value = cmat]
|
private |
keeps track of the gate counts
|
private |
qudit dimension
|
private |
keeps track of the gate depths
|
private |
gates
|
private |
keeps track of the measured qudits
|
private |
keeps track of the measurement counts
|
private |
measurements
|
private |
optional circuit name
|
private |
number of classical "dits"
|
private |
number of qudits
|
private |
type of each step