Class ParamCirc
Defined in File qml.hpp
Inheritance Relationships
Base Type
public qb::CircuitBuilder
(Class CircuitBuilder)
Class Documentation
-
class ParamCirc : public qb::CircuitBuilder
This class is used to build parametrized quantum circuits for execution as part of quantum machine learning algorithms. It can use any of the standard gates from qb::CircuitBuilder, as well as create input/ variational parameters using the single-parameter gates shown below.
Public Functions
-
ParamCirc(std::size_t numQubits, qml::DefaultAnsatzes ansatzType, std::size_t numAnsatzRepetitions, qb::VectorString varGates)
Creates a parametrized circuit with a pre-defined ansatz.
- Parameters:
numQubits – Number of qubits in the parametrised circuit (also currently sets number of input parameters) [size_t]
ansatzType – Type of parametric circuit ansatz to be created (currently only query opt. implemented) [qb::qml::DefaultAnsatzes]
numAnsatzRepetitions – Number of layers of the ansatz [size_t]
varGates – Which gates to be optimised variationally, given as a vector of gate names within {“Rx”,”Ry”,”Rz”} [qb::VectorString]
-
inline ParamCirc(size_t numQubits)
Constructs an empty parametrized circuit to be used with the circuit builder.
- Parameters:
numQubits – Number of qubits in the parametrised circuit
-
inline void RX(size_t index, char *type)
RX gate.
This method adds an x-axis rotation (RX) gate to the circuit.
The RX gate is defined by its action on the basis states
\[ RX(\theta)\ket{0} \rightarrow \cos(\theta/2)\ket{0} - i\sin(\theta/2)\ket{1} RX(\theta)\ket{1} \rightarrow -i\sin(\theta/2)\ket{0} + \cos(\theta/2)\ket{1} \]- Parameters:
index – the index of the qubit being acted on [size_t]
type – the type of input parameter (“input” or “variational”) [std::string]
-
inline void RY(size_t index, char *type)
RY gate.
This method adds a y-axis rotation (RY) gate to the circuit.
The RY gate is defined by its action on the basis states
\[ RY(\theta)\ket{0} \rightarrow \cos(\theta/2)\ket{0} + \sin(\theta/2)\ket{1} RY(\theta)\ket{1} \rightarrow -\sin(\theta/2)\ket{0} + \cos(\theta/2)\ket{1} \]- Parameters:
index – the index of the qubit being acted on [size_t]
type – the type of input parameter (“input” or “variational”) [std::string]
-
inline void RZ(size_t index, char *type)
RZ gate.
This method adds a z-axis rotation (RZ) gate to the circuit.
The RZ gate is defined by its action on the basis states
\[ RZ(\theta)\ket{0} \rightarrow e^{-i\theta/2}\ket{0} RZ(\theta)\ket{1} \rightarrow e^{i\theta/2}\ket{1} \]- Parameters:
index – the index of the qubit being acted on [size_t]
type – the type of input parameter (“input” or “variational”) [std::string]
-
inline void U1(size_t index, char *type)
U1 gate.
This method adds a phase (U1) gate to the circuit.
The U1 gate is defined by its action on the basis states
\[ U1(\theta)\ket{0} \rightarrow \ket{0} U1(\theta)\ket{1} \rightarrow e^{i\theta}\ket{1} \]- Parameters:
index – the index of the qubit being acted on [size_t]
type – the type of input parameter (“input” or “variational”) [std::string]
-
inline void CPhase(size_t ctrl_index, size_t target_index, char *type)
CPhase gate.
This method adds a controlled-U1 (CPhase) gate to the circuit.
The CPHase gate performs a U1 gate on the target qubit conditional on the control qubit being in the \(\ket{1}\) state. That is:
\[ CPhase(\theta)\ket{ab} \rightarrow \ket{a}U1(\theta)^a \ket{b} \]- Parameters:
ctrl_index – the index of the control qubit [size_t]
target_index – the index of the target qubit [size_t]
type – the type of input parameter (“input” or “variational”) [std::string]
-
inline void reupload()
Function for reuploading within the circuit, allowing for repeating the encoding ansatz.
-
inline std::size_t getNumInputs()
Return the number of input parameters.
-
inline std::size_t getNumParams()
Return the number of variational parameters.
-
inline std::size_t getNumQubits()
Return the number of qubits in the parametrized circuit.
-
inline std::size_t getNumAnsatzRepetitions()
Return the number of repetitions of the base ansatz (currently only has utility for DefaultAnsatz constructor).
Private Functions
-
void queryOptAnsatz()
-
std::vector<std::string> genParamNames()
-
void processAndAddGate(std::string gateName, std::vector<size_t> qubits, char *type)
Private Members
-
std::size_t numQubits_ = {0}
-
std::size_t numInputs_ = {0}
-
std::size_t numAnsatzRepetitions_{0}
-
qb::VectorString varGates_
-
std::size_t numParams_ = {0}
-
bool reuploading_{false}
-
std::shared_ptr<xacc::CompositeInstruction> encodingAnsatz_
-
std::vector<size_t> encParamIndices_
-
std::vector<size_t> varParamIndices_
Friends
- friend class QMLExecutor
-
ParamCirc(std::size_t numQubits, qml::DefaultAnsatzes ansatzType, std::size_t numAnsatzRepetitions, qb::VectorString varGates)