Backends¶
quantum_backend.h
¶
-
namespace iqsdk¶
-
struct DeviceConfig¶
- #include <quantum_backend.h>
Configurations for a quantum device. This is a struct that users of the SDK will make an instance of when creating a quantum device.
Sets default settings for classes constructed with DeviceConfig
Subclassed by iqsdk::CliffordSimulatorConfig, iqsdk::IqsConfig, iqsdk::TensorNetworkConfig
Public Functions
-
virtual bool isValid()¶
-
DeviceConfig()¶
-
DeviceConfig(const DeviceConfig&) = default¶
-
DeviceConfig &operator=(const DeviceConfig&) = default¶
-
DeviceConfig(DeviceConfig&&) = default¶
-
DeviceConfig &operator=(DeviceConfig&&) = default¶
-
virtual ~DeviceConfig() = default¶
-
virtual bool isValid()¶
-
class QuantumDevice¶
- #include <quantum_backend.h>
Public Functions
-
QuantumDevice() = default¶
-
virtual ~QuantumDevice() = default¶
-
QuantumDevice(const QuantumDevice&) = delete¶
-
QuantumDevice &operator=(const QuantumDevice&) = delete¶
-
QuantumDevice(QuantumDevice&&) = default¶
-
QuantumDevice &operator=(QuantumDevice&&) = default¶
-
QuantumDevice() = default¶
-
class Device¶
- #include <quantum_backend.h>
Subclassed by iqsdk::CliffordSimulator, iqsdk::CustomSimulator, iqsdk::SimulatorDevice
Public Functions
-
Device()¶
-
virtual ~Device()¶
-
bool isValid()¶
-
QRT_ERROR_T initialize(DeviceConfig &device_config)¶
Initialize the simulator instance with the given settings.
-
QRT_ERROR_T ready()¶
Specify that the next
quantum_kernel
called will be run on the device.
-
QRT_ERROR_T printVerbose(bool printVerbose)¶
Specify whether the device will or will not be put in verbose mode.
-
QRT_ERROR_T wait()¶
Wait for the device to stop running before continuing.
Useful in asynchronous mode, to ensure all
quantum_kernel
functions that are queued have finished running, and the appropriatecbit
variables have been set.Note
APIs that retrieve data from the device are synchronous. APIs that set device properties are asynchronous, so users may not always need to use this method.
Protected Functions
-
virtual int getDeviceType() = 0¶
-
Device()¶
-
class SimulatorDevice : public iqsdk::Device¶
- #include <quantum_backend.h>
Subclassed by iqsdk::FullStateSimulator, iqsdk::TensorNetworkSimulator
Public Functions
-
SimulatorDevice() = default¶
-
SimulatorDevice(const SimulatorDevice&) = delete¶
-
SimulatorDevice &operator=(const SimulatorDevice&) = delete¶
-
SimulatorDevice(SimulatorDevice&&) = delete¶
-
SimulatorDevice &operator=(SimulatorDevice&&) = delete¶
-
virtual ~SimulatorDevice() = default¶
-
std::vector<double> getProbabilities(std::vector<std::reference_wrapper<qbit>> &qids)¶
Return the conditional probabilities of the qubits given in
qids
.Useful for returning the conditional probabilities of certain qubits. For example, in a 4-qubit system \(\{q_0,q_1,q_2,q_3\}\), the probability associated with
QssIndex("|11>")
withqids={ref(q0); ref(q1)}
is the sum of the probabilities of being in state \(\ket{1100}\), \(\ket{1101}\), \(\ket{1110}\), or \(\ket{1111}\).- Parameters:
qids – A non-repeating list of qubit reference wrappers. Not all qubits need be included in
qids
vector, in which case getProbabilities() will return conditional probabilities.
-
QssMap<double> getProbabilities(std::vector<std::reference_wrapper<qbit>> &qids, std::vector<QssIndex> bases, double threshold = -1)¶
Return a
QssMap
of QssIndex todouble
.The same conditions on qids apply as above.
- Parameters:
bases – Specifies a subset of the states whose probability you are interested in. If nonempty, getProbabilities() will only return the probabilities associated with the given indices. If empty, it will return the probability associated with each quantum state.
threshold – Omits {state,double} pairs where the probability falls below the argument value. If specified,getProbabilities() will only return results whose probabilities are greater than or equal to the threshold. Consider retrieving \(2^N\) probabilities for large \(N\). It can become a cumbersome operation. Specifying a subset of states in the bases argument will cause speed up in the execution time of getProbabilities() by reducing the total number of operations. Specifying a threshold argument will increase the computational overhead due to performing a comparison of the probability and threshold.
-
double getProbability(std::vector<std::reference_wrapper<qbit>> &qids, QssIndex basis)¶
Return a single probability corresponding to the basis element given.
-
std::vector<std::vector<bool>> getSamples(unsigned int num_shots, std::vector<std::reference_wrapper<qbit>> &qids)¶
Return a vector with
num_shots
different samples of measurement results for the givenqubits_ids
.Generates samples from the full state vector at the end of the last run quantum basic block. Each sample is a vector of length
qids.size()
, whose value at indexi
corresponds to the measurement result of the qubitqids[i]
. Eachqbit
producesfalse
for the measurement result of the0
state, andtrue
for the measurement result of the1
state.Efficiently sample from the full-state data in the simulator without having to repeat the gates to prepare that state
num_shots
number of times.
-
std::vector<double> getSingleQubitProbs(std::vector<std::reference_wrapper<qbit>> &qids)¶
Return a vector of single qubit probabilities of length
qids.size()
.The order of the
single_qubit_probs
is given by the order of the qubits in theqids
vector.Useful if you want only the probabilities of each qubit being in state \(\ket{0}\) or \(\ket{1}\), ignoring entanglement with other qubits.
-
std::vector<std::complex<double>> getAmplitudes(std::vector<std::reference_wrapper<qbit>> &qids)¶
Return the complex amplitudes of the state space with respect to the order given by
qids
.- Parameters:
qids – a non-repeating list of all qubit ids in scope.
-
QssMap<std::complex<double>> getAmplitudes(std::vector<std::reference_wrapper<qbit>> &qids, std::vector<QssIndex> bases, double threshold = -1)¶
Same functionality as getAmplitudes()
The optional arguments
bases
andthreshold
are useful for querying subsets of a state space. If a user only wants to query the amplitudes of a subset of basis elements, specifying thosebases
will be significantly more efficient in time and space. If a user only wants amplitudes above a threshold, specifying athreshold
will significantly reduce the space required.- Parameters:
bases – If nonempty, only return the amplitudes associated with the given indices.
threshold – If given, only return results \(a+bi\) such that \(a^2+b^2 >= \text{threshold}\).
Public Static Functions
-
static QssMap<double> amplitudesToProbabilities(QssMap<std::complex<double>> &litudes)¶
Calling
amplitudesToProbabilities(getAmplitudes(...))
is equivalent to getProbabilities() but if a user wants to obtain both probabilities and amplitudes, this helper function can be useful.
-
static void displayProbabilities(std::vector<double> &probability, std::vector<std::reference_wrapper<qbit>> &qids)¶
Display to standard output the probability of observing the states composed by the qubits listed in
qids
.Intended to be passed the input and output pair from a past call to getProbabilities().
-
static void displayProbabilities(QssMap<double> &probability)¶
Display to standard output the probability value of observing each state represented by a QssIndex key in
probability
.
-
static void displayAmplitudes(std::vector<std::complex<double>> &litudes, std::vector<std::reference_wrapper<qbit>> &qids)¶
Display to standard output the complex amplitude for the states composed by the qubits listed in
qids
.Intended to be passed the input and output pair from a past call to getAmplitudes().
-
SimulatorDevice() = default¶
-
struct DeviceConfig¶
-
namespace qrt¶
quantum_clifford_simulator_backend.h
¶
-
namespace iqsdk
-
struct ErrSpec1Q¶
- #include <quantum_clifford_simulator_backend.h>
-
struct ErrSpec2Q¶
- #include <quantum_clifford_simulator_backend.h>
-
struct ErrSpecIdle¶
- #include <quantum_clifford_simulator_backend.h>
-
struct ErrorRates¶
- #include <quantum_clifford_simulator_backend.h>
Public Functions
-
ErrorRates() = default¶
-
ErrorRates(ErrSpec1Q NU, ErrSpec1Q U1, ErrSpec2Q U2, ErrSpecIdle I = ErrSpecIdle())¶
-
ErrorRates() = default¶
-
struct GateTimes¶
- #include <quantum_clifford_simulator_backend.h>
-
struct CliffordSimulatorConfig : public iqsdk::DeviceConfig¶
- #include <quantum_clifford_simulator_backend.h>
Public Functions
-
CliffordSimulatorConfig(unsigned int seed, bool use_errors = false, ErrorRates error_rates = {}, GateTimes gate_times = {}, bool verbose = false, bool synchronous = true)¶
Constructor for Clifford Simulator Configuration.
-
CliffordSimulatorConfig(unsigned int seed, bool use_errors = false, ErrorRates error_rates = {}, GateTimes gate_times = {}, bool verbose = false, bool synchronous = true)¶
-
class CliffordSimulator : public iqsdk::Device¶
- #include <quantum_clifford_simulator_backend.h>
Public Functions
-
CliffordSimulator()¶
-
CliffordSimulator(iqsdk::DeviceConfig &device_config)¶
-
CliffordSimulator(const CliffordSimulator&) = delete¶
-
CliffordSimulator &operator=(const CliffordSimulator&) = delete¶
-
CliffordSimulator(CliffordSimulator&&) = delete¶
-
CliffordSimulator &operator=(CliffordSimulator&&) = delete¶
-
~CliffordSimulator() = default¶
Private Functions
-
virtual int getDeviceType()¶
-
CliffordSimulator()¶
-
struct ErrSpec1Q¶
quantum_custom_backend.h
¶
-
namespace iqsdk
-
class CustomInterface¶
- #include <quantum_custom_backend.h>
Public Functions
-
virtual void RXY(qbit q, double theta, double phi) = 0¶
Rotation in the XY plane, ideally described by the 2x2 matrix:
\[\begin{split} R_{XY}(\theta, \phi) = \begin{bmatrix} \cos(\theta/2) & -i \exp(-i \phi) \sin(\theta/2) \\ -i \exp(i \phi) \sin(\theta/2) & \cos(\theta/2) \end{bmatrix} \end{split}\]
-
virtual void RZ(qbit q, double angle) = 0¶
Rotation around the Z axis, ideally described by the 2x2 matrix:
\[\begin{split} R_Z(\theta) = \begin{bmatrix} \cos(\theta/2) - i \sin(\theta/2) & 0 \\ 0 & \cos(\theta/2) + i \sin(\theta/2) \end{bmatrix} \end{split}\]
-
virtual void CPhase(qbit ctrl, qbit target, double angle) = 0¶
CPHASE gate ideally corresponding to the 4x4 matrix:
\[\begin{split} CPHASE(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & \exp(-i \theta) \end{bmatrix} \end{split}\]
-
virtual void SwapA(qbit q1, qbit q2, double angle) = 0¶
SWAP-type gate, with arbitrary angle \(\alpha\). Ideally it corresponds to the 4x4 matrix:
\[\begin{split} SWAP(\alpha) = \frac{1}{2} \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 1+\exp(i\alpha) & 1-\exp(i\alpha) & 0 \\ 0 & 1-\exp(i\alpha) & 1+\exp(i\alpha) & 0 \\ 0 & 0 & 0 & 2 \end{bmatrix} \end{split}\]Special cases are the common SWAP gate associated with \(\alpha=0\):
\[\begin{split} SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{split}\]And its square root for \(\alpha=\pi/2\):
\[\begin{split} \sqrt{SWAP} = SWAP\left(\frac{\pi}{2}\right) = \frac{1}{2} \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 1+i & 1-i & 0 \\ 0 & 1-i & 1+i & 0 \\ 0 & 0 & 0 & 2 \end{bmatrix} \end{split}\]
-
CustomInterface() = default¶
-
CustomInterface(const CustomInterface&) = default¶
-
CustomInterface &operator=(const CustomInterface&) = default¶
-
CustomInterface(CustomInterface&&) = default¶
-
CustomInterface &operator=(CustomInterface&&) = default¶
-
virtual ~CustomInterface() = default¶
-
virtual void RXY(qbit q, double theta, double phi) = 0¶
-
class CustomSimulator : public iqsdk::Device¶
- #include <quantum_custom_backend.h>
Public Functions
-
CustomSimulator()¶
-
CustomSimulator(iqsdk::DeviceConfig &device_config)¶
-
CustomSimulator(const CustomSimulator&) = delete¶
-
CustomSimulator &operator=(const CustomSimulator&) = delete¶
-
CustomSimulator(CustomSimulator&&) = delete¶
-
CustomSimulator &operator=(CustomSimulator&&) = delete¶
-
~CustomSimulator() = default¶
-
iqsdk::CustomInterface *getCustomBackend()¶
Public Static Functions
-
template<typename T, typename ...Ts>
static inline CustomSimulator *createSimulator(std::string device_id, Ts... args)¶
-
template<typename T, typename ...Ts>
static inline QRT_ERROR_T registerCustomInterface(std::string device_id, Ts... args)¶
Private Functions
-
virtual int getDeviceType()¶
Private Static Functions
-
static QRT_ERROR_T registerCustomInterfaceWrapper(std::function<CustomInterface*()>, std::string device_id)¶
-
CustomSimulator()¶
-
class CustomInterface¶
quantum_full_state_simulator_backend.h
¶
-
namespace iqsdk
Functions
-
std::vector<std::complex<double>> ParseChiMatrixFromCsvFiles(unsigned num_qubits, std::string fname_real, std::string fname_imag)¶
Utility function to load a process matrix from a pair of CSV files.
The process matrix is a square matrix of size \(4^n x 4^n\), with \(n\) being the
num_qubits
value. The entries are complex and this function expects the real and imaginary part to be stored in separate files. Each files corresponds to comma separated values, with one row stored in each line.
Variables
-
static const struct IqsCustomOp k_iqs_ideal_op = {0, 0, 0, 0, {}, "ideal", 0, 0, 0, 0}¶
Constant iqsdk::IqsCustomOp object corresponding to an ideal operation.
-
struct IqsCustomOp¶
- #include <quantum_full_state_simulator_backend.h>
Simplified description of custom IQS operation.
-
struct IqsConfig : public iqsdk::DeviceConfig¶
- #include <quantum_full_state_simulator_backend.h>
Configuration struct for IQS backend.
Users of the SDK can use an instance of this struct to create an IqsDevice. As part of the device, one can specify its noise model by explicitly defining the backend behavior corresponding to the various quantum macroinstructions (i.e. gates and SPAM operations).
Public Functions
-
virtual bool isValid()¶
Whether given config instance is valid.
Public Members
-
int num_qubits¶
Number of qubits in simulation.
-
std::string simulation_type¶
Type of simulation to be run.
Valid simulation types are: “noiseless”, “depolarizing”, “custom”
-
double depolarizing_rate¶
Depolarizing rate for noisy simulation.
-
bool use_custom_seed¶
Whether custom seed for RNG is used.
-
std::function<IqsCustomOp(unsigned)> MeasZ =
[](unsigned) {return k_iqs_ideal_op;}
¶ One-qubit measurement in the Z basis.
-
std::function<IqsCustomOp(unsigned)> PrepZ =
[](unsigned) {return k_iqs_ideal_op;}
¶ One-qubit state preparation in the Z basis (state \(\ket{0}\))
-
std::function<IqsCustomOp(unsigned, double, double)> RotationXY =
[](unsigned, double, double) {return k_iqs_ideal_op;}
¶ Rotation in the XY plane, ideally described by the 2x2 matrix:
\[\begin{split} R_{XY}(\theta, \phi) = \begin{bmatrix} \cos(\theta/2) & -i \exp(-i \phi) \sin(\theta/2) \\ -i \exp(i \phi) \sin(\theta/2) & \cos(\theta/2) \end{bmatrix} \end{split}\]
-
std::function<IqsCustomOp(unsigned, double)> RotationZ =
[](unsigned, double ) {return k_iqs_ideal_op;}
¶ Rotation around the Z axis, ideally described by the 2x2 matrix:
\[\begin{split} R_Z(\theta) = \begin{bmatrix} \cos(\theta/2) - i \sin(\theta/2) & 0 \\ 0 & \cos(\theta/2) + i \sin(\theta/2) \end{bmatrix} \end{split}\]
-
std::function<IqsCustomOp(unsigned, unsigned, double)> ISwapRotation =
[](unsigned, unsigned, double) {return k_iqs_ideal_op;}
¶ SWAP-type gate, with arbitrary angle. Ideally it corresponds to the 4x4 matrix:
\[\begin{split} SWAP(\alpha) = \frac{1}{2} \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 1+\exp(i\alpha) & 1-\exp(i\alpha) & 0 \\ 0 & 1-\exp(i\alpha) & 1+\exp(i\alpha) & 0 \\ 0 & 0 & 0 & 2 \end{bmatrix} \end{split}\]Special cases are the common SWAP gate associated with \(\alpha=0\):
\[\begin{split} SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{split}\]And its square root for \(\alpha=\pi/2\):
\[\begin{split} \sqrt{SWAP} = SWAP\left(\frac{\pi}{2}\right) = \frac{1}{2} \begin{bmatrix} 2 & 0 & 0 & 0 \\ 0 & 1+i & 1-i & 0 \\ 0 & 1-i & 1+i & 0 \\ 0 & 0 & 0 & 2 \end{bmatrix} \end{split}\]
-
std::function<IqsCustomOp(unsigned, unsigned, double)> CPhaseRotation =
[](unsigned, unsigned, double) {return k_iqs_ideal_op;}
¶ CPHASE gate ideally corresponding to the 4x4 matrix:
\[\begin{split} CPHASE(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & \exp(-i \theta) \end{bmatrix} \end{split}\]
-
virtual bool isValid()¶
-
class FullStateSimulator : public iqsdk::SimulatorDevice¶
- #include <quantum_full_state_simulator_backend.h>
Class with API calls to both set up a quantum simulator device and access the underlying quantum state during simulation.
Note
re FullStateSimulator::getSamples(): Measurement with MeasX, MeasY, or MeasZ collapses the quantum state, so if a qubit that has recently been measured is included in
qids,
this will always return the same value that previously resulted from measurementNote
Collecting data with IQS expects any qids provided to be from a previously-run quantum kernel
Public Functions
-
FullStateSimulator()¶
-
FullStateSimulator(DeviceConfig &device_config)¶
-
FullStateSimulator(const FullStateSimulator&) = delete¶
-
FullStateSimulator &operator=(const FullStateSimulator&) = delete¶
-
FullStateSimulator(FullStateSimulator&&) = delete¶
-
FullStateSimulator &operator=(FullStateSimulator&&) = delete¶
-
virtual ~FullStateSimulator() = default¶
Private Functions
-
virtual int getDeviceType()¶
-
FullStateSimulator()¶
-
std::vector<std::complex<double>> ParseChiMatrixFromCsvFiles(unsigned num_qubits, std::string fname_real, std::string fname_imag)¶
quantum_tensor_network_backend.h
¶
-
namespace iqsdk
-
struct TensorNetworkConfig : public iqsdk::DeviceConfig¶
- #include <quantum_tensor_network_backend.h>
Public Functions
-
TensorNetworkConfig(bool verbose = false, bool synchronous = true)¶
Constructor for Tensor Network Configuration.
-
TensorNetworkConfig(bool verbose = false, bool synchronous = true)¶
-
class TensorNetworkSimulator : public iqsdk::SimulatorDevice¶
- #include <quantum_tensor_network_backend.h>
Public Functions
-
TensorNetworkSimulator()¶
-
TensorNetworkSimulator(iqsdk::DeviceConfig &device_config)¶
-
TensorNetworkSimulator(const TensorNetworkSimulator&) = delete¶
-
TensorNetworkSimulator &operator=(const TensorNetworkSimulator&) = delete¶
-
TensorNetworkSimulator(TensorNetworkSimulator&&) = delete¶
-
TensorNetworkSimulator &operator=(TensorNetworkSimulator&&) = delete¶
-
~TensorNetworkSimulator() = default¶
-
void draw()¶
Private Functions
-
virtual int getDeviceType()¶
-
TensorNetworkSimulator()¶
-
struct TensorNetworkConfig : public iqsdk::DeviceConfig¶
Functional Language Extension for Quantum (FLEQ)¶
datalist.h
¶
DataList definition
Defines
-
LLVM_CLANG_QUANTUM_DATALIST_H¶
-
STRINGIFYDATA(D)¶
-
import_with_name_begin(NAME)¶
-
import_with_name_end(NAME)¶
-
namespace datalist¶
Functions
- template<class Type> Type *WRAP_ATTR IQC_alloca (const DataList name, const unsigned long size)
-
struct DataList¶
- #include <datalist.h>
Public Functions
- inline int WRAP_ATTR to_int () const
Returns the integer corresponding to current
DataList
.
- inline double WRAP_ATTR to_double () const
Returns the
double
corresponding to the currentDataList
.
- inline bool WRAP_ATTR to_bool () const
Returns the boolean corresponding to the current
DataList
.
- inline char WRAP_ATTR operator[] (unsigned long i) const
Index into a
DataList
.
- inline char WRAP_ATTR operator* () const
Dereference a
DataList
.
- inline bool WRAP_ATTR empty () const
Returns
true
if the size of theDataList
is 0.
- inline unsigned long WRAP_ATTR size () const
Return the size of the current
DataList
.
- inline const DataList WRAP_ATTR operator() (unsigned long a, unsigned long b) const
Produces a slice of a
DataList
, starting from indexa
and ending at indexb-1
.Example: If
d = "uvxyz"
thend(2,4) = "xy"
.
- inline const DataList WRAP_ATTR operator() (unsigned long from, const DataList to) const
Produces a slice of a
DataList
.
- inline const DataList WRAP_ATTR operator() (const DataList from, unsigned long to) const
Produces a slice of a
DataList
.
- inline const DataList WRAP_ATTR operator() (const DataList from, const DataList to) const
Produces a slice of a
DataList
.
- inline const DataList WRAP_ATTR operator++ () const
Shifts the
DataList
right by 1.
- inline const DataList WRAP_ATTR operator<< (const unsigned i) const
Shifts the
DataList
left byi
.Example:
"abc" << 1 = "ab"
.
- inline const DataList WRAP_ATTR operator>> (const unsigned i) const
Shifts the
DataList
right byi
.Example:
"abc" >> 1 = "bc"
.
- inline unsigned long WRAP_ATTR find (const DataList d) const
Returns the index of the first occurrence of
d
in the currentDataList
.
- inline unsigned long WRAP_ATTR find_last (const DataList d) const
Returns the index of the last occurrence of
d
in the currentDataList
.
- inline unsigned long WRAP_ATTR find_any (const DataList d) const
Returns the index of the first occurrence of any of the characters in
d
in the currentDataList
.Example:
DataList("xyz20").find_any("012")
will return the index 3, because"xyz20"[3] = 2
.
- inline unsigned long WRAP_ATTR find_any_last (const DataList d) const
Returns the index of the last occurrence of any of the characters in
d
in the currentDataList
.
- inline unsigned long WRAP_ATTR find_not (const DataList d) const
Returns the index of the first character not matching
d
. Will return 0 ifd
is not a prefix of the currentDataList
.
- inline unsigned long WRAP_ATTR find_not_last (const DataList d) const
Returns the index of the last character not matching
d
. Will returnsize()
ifd
is not a suffix of the currentDataList
.
- inline const DataList WRAP_ATTR next (const DataList d) const
Returns the
DataList
sliced beginning at the first occurrence ofd
.Example:
DataList("find this 123 or this 345").next("this") = "this 123 or this 345"
- template<typename... Args> inline const DataList WRAP_ATTR next (const DataList d, Args... ds) const
Returns the DataList sliced beginning at the next occurrence of any of the given arguments. Example:
DataList("The quick brown fox.").next("fox", "quick") = "quick brown fox." DataList("The quick brown fox.").next("fox", "house") = "fox."
- inline const DataList WRAP_ATTR after_next (const DataList d) const
Returns the
DataList
occurring directly after the first occurrence ofd
in the currentDataList
.
- template<typename... Args> inline const DataList WRAP_ATTR after_next (const DataList d, Args... ds) const
Returns the
DataList
sliced starting after the next occurrence ofd
.Example:
DataList("find this 123").next("this") = " 123"
- inline const DataList WRAP_ATTR next_not (const DataList d) const
Returns the
DataList
occurring after the indexfind_not(d)
- inline const DataList WRAP_ATTR next_block (const DataList d) const
Returns the first
DataList
block whose elements all match any of the characters ind
.For example,
next_block("0123456789")
will return the first integer in the currentDataList
.
- inline const DataList WRAP_ATTR last (const DataList d) const
Returns the
DataList
sliced beginning at the last occurrence ofd
.Example:
DataList("find this 123 or this 345").last("this") = "this 345"
- template<typename... Args> inline const DataList WRAP_ATTR last (const DataList d, Args... ds) const
Returns the
DataList
sliced beginning at the last occurrence of any of the given arguments.Example:
DataList("find this or this 123").last("1", "2", "3") = "3"
- inline const DataList WRAP_ATTR after_last (const DataList d) const
Returns the slice of the current
DataList
after the last instance ofd
.
- template<typename... Args> inline const DataList WRAP_ATTR after_last (const DataList d, Args... ds) const
Returns the
DataList
sliced beginning immediately after the last occurrence ofd
.Example:
DataList("find this 123 or this 345").last("this") = " 345"
- inline const DataList WRAP_ATTR last_not (const DataList d) const
Returns the slice of the current
DataList
after the indexfind_not_last(d)
.
- inline const DataList WRAP_ATTR last_block (const DataList d) const
Returns the last
DataList
block whose elements all match any of the characters ind
.For example,
last_block("0123456789")
will return the last integer in the currentDataList
.
- inline bool WRAP_ATTR contains (const DataList d) const
Returns
true
if the currentDataList
containsd
.
- inline unsigned long WRAP_ATTR count (const DataList d) const
Returns the number of instances of
d
in the currentDataList
.
- template<typename... Args> inline unsigned long WRAP_ATTR count (const DataList d, Args... ds) const
Returns the number of instances of any of the arguments in the in the current
DataList
.
- inline const DataList WRAP_ATTR trim (const DataList start=DataList(" "), const DataList end=DataList(" ")) const
Returns the
DataList
stripped of beginning and trailing characters. Ifstart
andend
are not the first and/or last characters ofname
respectively, thentrim
will have no effect.
Public Static Functions
- static inline const DataList WRAP_ATTR empty_list ()
Returns an empty
DataList
.
Friends
- inline friend int WRAP_ATTR _i (const DataList a)
Returns the integer corresponding to the
DataList
a
.- Parameters:
a – A
DataList
representing an integer
- inline friend double WRAP_ATTR _d (const DataList a)
Returns the
double
corresponding to theDataList
a
.- Parameters:
a – A
DataList
representing a floating-point number
- inline friend bool WRAP_ATTR _b (const DataList a)
Returns the boolean corresponding to the
DataList
a
.- Parameters:
a – A
DataList
representing a boolean
- inline friend unsigned long WRAP_ATTR size (const DataList a)
Return the size of the
DataList
.
- inline friend const DataList WRAP_ATTR operator+ (const DataList a, const DataList b)
Concatenates two
DataLists
together.Example:
"abc" + "xyz" = "abcxyz"
- inline friend const friend bool WRAP_ATTR operator== (const DataList a, const DataList b)
Compares two
DataLists
for equality.
- inline friend std::string WRAP_ATTR to_string (const DataList a)
Converts a
DataList
into a C++ string.
- inline friend const char *WRAP_ATTR to_char_array (const DataList a)
Converts a
DataList
into a C string.
- template<class Type> inline friend Type *WRAP_ATTR IQC_alloca (const DataList name, const unsigned long size)
Generate an array of
Type`
objects of sizeN
with IR namename
(for printing and debugging purposes) and return a pointer to the first element. No additional memory management is required. The scope of the variable will be the same as that of the evaluation call.
-
namespace qexpr¶
qexpr.h
¶
Basic set of functions which return QExpr’s
Defines
-
LLVM_CLANG_QEXPR_H¶
-
this_as_expr¶
Returns the contents of the current
quantum_kernel
function as aQExpr
.Note
Use of
this_as_expr
requires the use of thePROTECT
function attribute.
-
namespace qexpr
Functions
-
QExpr exitAtCompile(datalist::DataList d = datalist::DataList::empty_list())¶
Raise a compile-time error.
-
QExpr exitAtRuntime(datalist::DataList d = datalist::DataList::empty_list())¶
Raise a runtime error.
-
QExpr printDataList(datalist::DataList d, QExpr e)¶
Print the
DataList
at compile-time and returne
.
- QExpr WRAP_ATTR identity ()
A
QExpr
that has no effect on the quantum state.
- QExpr WRAP_ATTR global_phase (double angle)
A
QExpr
that applies a global phase.
-
template<auto *F, class ...Args>
QExpr convert(Args&&... args)¶ Convert a
quantum_kernel
function to a quantum kernel expression ( aQExpr
).
- void WRAP_ATTR eval_hold (QExpr e)
Evaluate a
QExpr
, ensuring the quantum state is maintained after evaluation.
- void WRAP_ATTR eval_release (QExpr e)
Evaluate a
QExpr
, making no guarantees about the quantum state after evaluation. Equivalent torelease_quantum_state
for quantum_kernel functions.
- QExpr WRAP_ATTR _H (qbit &q)
QExpr
implementing a Hadamard gate
- QExpr WRAP_ATTR _X (qbit &q)
QExpr
implementing a Pauli X gate
- QExpr WRAP_ATTR _Y (qbit &q)
QExpr
implementing a Pauli Y gate
- QExpr WRAP_ATTR _Z (qbit &q)
QExpr
implementing a Pauli Z gate
- QExpr WRAP_ATTR _S (qbit &q)
QExpr
implementing an S gate
- QExpr WRAP_ATTR _Sdag (qbit &q)
QExpr
implementing an inverse S gate
- QExpr WRAP_ATTR _T (qbit &q)
QExpr
implementing a T gate
- QExpr WRAP_ATTR _Tdag (qbit &q)
QExpr
implementing an inverse T gate
- QExpr WRAP_ATTR _RX (qbit &q, double angle)
QExpr
implementing an X rotation
- QExpr WRAP_ATTR _RY (qbit &q, double angle)
QExpr
implementing a Y rotation
- QExpr WRAP_ATTR _RZ (qbit &q, double angle)
QExpr
implementing a Z rotation
- QExpr WRAP_ATTR _CZ (qbit &ctrl, qbit &tgt)
QExpr
implementing a controlled-Z rotation
- QExpr WRAP_ATTR _CNOT (qbit &ctrl, qbit &tgt)
QExpr
implementing a controlled-X rotation
- QExpr WRAP_ATTR _SWAP (qbit &q1, qbit &q2)
QExpr
implementing a SWAP gate
- QExpr WRAP_ATTR _Toffoli (qbit &q1, qbit &q2, qbit &q3)
QExpr
implementing a Toffoli gate
- QExpr WRAP_ATTR _PrepX (qbit &q)
QExpr
implementing a preparation in the X basis
- QExpr WRAP_ATTR _PrepY (qbit &q)
QExpr
implementing a preparation in the Y basis
- QExpr WRAP_ATTR _PrepZ (qbit &q)
QExpr
implementing a preparation in the Z basis
- QExpr WRAP_ATTR _MeasX (qbit &q, cbit &c)
QExpr
implementing a measurement in the X basis
- QExpr WRAP_ATTR _MeasY (qbit &q, cbit &c)
QExpr
implementing a measurement in the Y basis
- QExpr WRAP_ATTR _MeasZ (qbit &q, cbit &c)
QExpr
implementing a measurement in the Z basis
- QExpr WRAP_ATTR _CPhase (qbit &ctrl, qbit &tgt, double angle)
QExpr
implementing a CPhase gate
- QExpr WRAP_ATTR _RXY (qbit &q, double theta, double phi)
QExpr
implementing a two-axis rotation
- QExpr WRAP_ATTR _SwapA (qbit &q1, qbit &q2, double angle)
QExpr
implementing a SwapA gate
- QExpr WRAP_ATTR join (QExpr e1, QExpr e2)
Concatenate two QExprs in composition order. Example:
join(_H(q), _PrepZ(q))
is equivalent to the circuit:|q> --- PrepZ --- H ---
- QExpr WRAP_ATTR bind (QExpr e1, QExpr e2)
Concatenate two QExprs in composition order, with a circuit barrier. Measurement outcomes in
e2
will be available toe1
. Will not optimize across the barrier.
- QExpr WRAP_ATTR invert (QExpr e)
Implement the inverse of the
QExpr
e
.- Parameters:
e – A unitary
QExpr
.
- QExpr WRAP_ATTR power (unsigned int n, QExpr e)
Concatenate
e
with itselfn
times. Assumesn
is a constant resolvable at compile-time. Example:power(3,e) = join(e, join(e, e))
- QExpr WRAP_ATTR control (qbit &ctrl, QExpr e)
Control
e
by the qubitctrl
. Assumese
is unitary. Example:control(ctrl, _H(q))
implements:|ctrl> --- o --- | |q> --- H ---
- Parameters:
ctrl – A qubit that does not appear in
e
.e – A Unitary
QExpr
.
- QExpr WRAP_ATTR control (qbit &ctrl, bool control_if, QExpr e)
Control the unitary
e
byctrl = |control_if>
. Example:control(ctrl, false, _H(q))
implements:|ctrl> --- X --- o --- X --- | |q> --------- H ---------
- Parameters:
ctrl – A qubit that does not appear in
e
.e – A unitary
QExpr
.
- QExpr WRAP_ATTR control (qbit ctrls[], QExpr e)
Control
e
by the entire qubit arrayctrls
. Example: ifctrls = {a,b}
thencontrol(ctrls, _X(q))
implements:|a> --- o --- | |b> --- o --- | |q> --- X ---
- Parameters:
ctrls – A qubit array whose elements do not appear in
e
.e – A unitary
QExpr
.
- QExpr WRAP_ATTR control (qbit ctrls[], unsigned int control_on, QExpr e)
Control the unitary
e
byctrls = |control_on>
, wherecontrol_on
is an index corresponding to a basis state. (SeeQssIndex
for details of the index encoding.) Example: Ifctrls = {a,b}
andcontrol_on = QssIndex("|01>").getIndex()
thencontrol(ctrls, control_on, _X(q))
implements:|a> --- X --- o --- X --- | |b> --------- o --------- | |q> --------- X ---------
- Parameters:
ctrls – A qubit array that whose elements do not appear in e
e – A unitary QExpr.
- QExpr WRAP_ATTR control (const qlist::QList &ctrls, QExpr e)
- QExpr WRAP_ATTR control (const qlist::QList &ctrls, unsigned int control_on, QExpr e)
- QExpr WRAP_ATTR qIf (qbit &ctrl, QExpr eT, QExpr eF)
Control
eT
byctrl=true
andeF
byctrl=false
.- Parameters:
ctrl – A qubit not appearing in
eT
oreF
.eT – A unitary
QExpr
.eF – A unitary
QExpr
.
- QExpr WRAP_ATTR cIf (bool b, QExpr eTrue, QExpr eFalse)
If
b=true
, executeeTrue
, otherwise executeeFalse
.- Parameters:
b – A runtime boolean value.
- QExpr WRAP_ATTR cIfTrue (bool b, QExpr eTrue)
If
b=true
, executeeTrue
, otherwise do nothing.- Parameters:
b – A runtime boolean value.
- QExpr WRAP_ATTR cIfFalse (bool b, QExpr eFalse)
If
b=false
, executeeFalse
, otherwise do nothing.- Parameters:
b – A runtime boolean value.
- void WRAP_ATTR let (const char key[], QExpr e)
Assign the
QExpr
e
to a string key.
- QExpr WRAP_ATTR get (const char key[])
Return the
QExpr
previously assigned to the key.
- QExpr WRAP_ATTR fence (QExpr e)
Implement a barrier/fence after the
QExpr
e
.
- QExpr WRAP_ATTR printQuantumLogic (QExpr e)
Print out the PCOAST graph(s) generated by
e
at compile-time, and returne
.
-
template<auto *F>
struct Converter¶ - #include <qexpr.h>
Class that supports converting a
quantum_kernel
function into aQExpr
. Implements theconvert
function.
-
template<class ...Args>
struct Converter<F>¶ - #include <qexpr.h>
Class that supports converting a
quantum_kernel
function into aQExpr
. Implements theconvert
function.Note the circuitous method is because we require qk function argument deduction from the pointer, and C++ does not allow for partial specialization of functions.
- Template Parameters:
F – A
quantum_kernel
function that returnsvoid
Public Functions
- inline PROTECT QExpr convert (Args... args) const
Convert a
quantum_kernel
function into aQExpr
.- Parameters:
...args – Arguments to be passed to
F
-
QExpr exitAtCompile(datalist::DataList d = datalist::DataList::empty_list())¶
qexpr_utils.h
¶
Utilities for working with quantum kernel expressions.
-
namespace qexpr
Functions
- template<typename QExprFun, typename... Args> PROTECT QExpr map (QExprFun f, qlist::QList qs, Args... args) noexcept
Map a
QExpr
function over each element in aQList
.The input function
f
should take in a qubit and some additional arguments, and returns aQExpr
. In the simplest case, where no additional arguments are given,map(f,qs)
will expand tof(qs[0]) + f(qs[1]) + ... + f(qs[size(qs)-1])
The additional arguments to
map
are either array arguments or scalar arguments.Array arguments are either
QList
or pointer typesT*
;map
will map the functionf
over each element of the array type.map
expects the size of all array arguments to be at least as large as the initialQList
argumentqs
; any additional elements of the array arguments will be ignored.All other types of arguments are treated as scalar arguments, and are passed to each invocation of
f
.As an example, suppose we have (1) a
QList
qs
; (2) anint
x
; (3) aQList
rs
; and (4) a boolean arraybs
. In a call tomap
,x
will be treated as a scalar argument andrs
andbs
as array arguments. Letf
be a function with signatureQExpr f(qbit q, int x, qbit r, bool b)
; Thenmap(f,qs,x,rs,bs)
will expand tof(qs[0], x, rs[0], bs[0]) + ... + f(qs[n-1], x, rs[n-1], bs[n-1])
wheren = qs.size()
.- Template Parameters:
QExprFun – The type of
f
...Args – The type of the argument list
- Parameters:
f – A function of type
QExpr f(qbit q, ...)
qs – A
QList
...args – A collection of array and scalar arguments.
- Returns:
The
QExpr
obtained by mappingf
over all qubits inqs
- template<typename QExprFun, typename... Args> PROTECT QExpr map1 (QExprFun f, qlist::QList qs, Args... args) noexcept
mapN(f,qs,...)
maps aQExpr
functionf
overarrays
arguments, the first of which must be aQList
. Additional arguments are treated as scalar arguments, and passed tof
directly.Example (
map1
): Letf
be a function with signatureQExpr f(qubit& q, int x);
Ifqs = {a,b,c}
is aQList
andn
is anint
, thenmap1(f, qs, n)
implementsf(a,n) + f(b,n) + f(c,n)
Example (
map2
): Letf
be a function with signatureQExpr f(qbit& q, qbit& r, qbit& s);
Letqs = {q1, q2, q3}
andrs = {r1, r2, r3}
beQLists
, and lets
be a single qubit. Thenmap2(f, qs, rs, s)
will expand tof(q1, r1, s) + f(q2, r2, s) + f(q3, r3, s)
. We see thatmap2(f, qs, rs, s)
treatss
as a scalar argument, since it is the third argument afterf
;map2
only maps the function over the first two arguments.
- template<typename QExprFun, typename ArrayArg, typename... Args> PROTECT QExpr map2 (QExprFun f, qlist::QList qs, ArrayArg xs, Args... args) noexcept
- template<typename QExprFun, typename ArrayArg1, typename ArrayArg2, typename... Args> PROTECT QExpr map3 (QExprFun f, qlist::QList qs, ArrayArg1 xs, ArrayArg2 ys, Args... args) noexcept
- template<typename QExprFun, typename ArrayArg1, typename ArrayArg2, typename ArrayArg3, typename... Args> PROTECT QExpr map4 (QExprFun f, qlist::QList qs, ArrayArg1 xs, ArrayArg2 ys, ArrayArg3 zs, Args... args) noexcept
- template<typename QExprFun, typename... Args> PROTECT QExpr mapWithIndex (QExprFun f, qlist::QList qs, Args... args)
Map over a
QList
of qubits with a function that takes both a qubit and the index at which it appears in the overallQList
.Example: Let
f
be a function that takes a qubit and an integer, and returns aQExpr
. Letqs = {a,b,c}
be aQList
. ThenmapWithIndex(qk, qs)
implementsqk(a,0) + qk(b,1) + qk(c,2)
- Parameters:
f – A
QExpr
function that takes a qubitq
[i], the indexi
, and optionally additional argumentsqs – The
QList
to map over
- template<typename QExprFun, typename QExprReturn, typename... Args> PROTECT QExprReturn fold (QExprFun k, qlist::QList qs, QExprReturn base, Args... args)
Recursively fold a function over a list of qubits.
Recursively performs a right fold (in the functional programming sense) over a
QList
of qubits. Example:fold(k, {q0, q1, q2}, b) = k(q0, k(q1, k(q2, b)))
- Template Parameters:
QExprFun – The type of
k
QExprReturn – The return type of the fold. Must either be
QExpr
or a type that contains aQExpr
, such as a pair or tuple type where one component isQExpr
- Parameters:
k – A function that takes a qubit and an argument of type
QExprReturn
, and produces a newQExprReturn
qs – A
QList
of qubitsbase – A value of type
QExprReturn
, returned whenqs
is emptyqargs... – A list of additional arguments to
k
- Returns:
-
QExpr conjugate(QExpr e1, QExpr e2)¶
Conjugate
e2
bye1
; i.e. return theQExpr
invert(e1) + e2 + e1
- Parameters:
e1 – A unitary
QExpr
.e2 – A
QExpr
. Need not be unitary.
- template<typename QExprFun, typename... Args> PROTECT QExpr mapDataList (QExprFun f, datalist::DataList sep, datalist::DataList d, Args... args)
Map a
QExpr
function over a DataList with entries separated bysep
.For example, if
sep
is";"
andd
is"d1; ... ; dn"
, will return theQExpr
f(d1,args...) + ... + f(dn, args...)
.- Parameters:
f – A function that takes as an argument (1) a
DataList
; (2) some number of additional argumentsargs
…sep – A single-character
DataList
that separatesd
into pieces to be passed tof
.d – The
DataList
to be mapped over...args – Additional scalar arguments to be passed directly to every invocation of
f
.
- Returns:
- template<typename QExprFun, typename... Args> PROTECT QExpr mapDataList (datalist::DataList startToken, datalist::DataList endToken, QExprFun f, datalist::DataList sep, datalist::DataList d, Args... args)
Map a
QExpr
function over aDataList
representing a list with entries separated by the tokensep
, and optionally starting with the tokenstartToken
and ending with the tokenendToken
.For example,
mapDataList("{", "}", f, ";", "{d1; d2; d3}", arg)
, will return theQExpr
f(d1,arg) + f(d2,arg) + f(d3, arg)
.If
startToken
and/orendToken
are not found, will still parse.
qlist.h
¶
QList definition
Defines
-
GET_LISTABLE(_1, _2, _3, NAME, ...)¶
-
RM_PARANS(...)¶
-
listable(...)¶
-
listable_array_init(NAME, NUM, INIT)¶
-
listable_array(NAME, NUM)¶
-
listable_scalar(NAME)¶
-
namespace qlist¶
Functions
-
const QList slice(const QList&, unsigned long, unsigned long)¶
Example: If
qs = {a,b,c,d,e}
thenslice(qs,2,4) = {c,d}
.
- unsigned long WRAP_ATTR size (qbit *reg)
- bool WRAP_ATTR qbits_equal (qbit &q1, qbit &q2)
Compare two qbits for equality.
-
struct QList¶
- #include <qlist.h>
Public Functions
- inline qbit WRAP_ATTR & operator[] (unsigned long i) const
Index into the
QList
at indexi
. Example: ifqs={a,b,c}
thenqs[1] = b
.
- inline WRAP_ATTR qbit & operator* () const
Index into the
QList
at index0
.
- inline unsigned long WRAP_ATTR size () const
Return the size of the
QList
.
- inline qbit WRAP_ATTR & at (unsigned long i) const
Index into the
QList
at indexi
.
- inline const QList WRAP_ATTR operator() (unsigned long a, unsigned long b) const
Produces a slice of a
QList
, starting from indexa
and ending at indexb-1
.Example: If
qs = {u,v,x,y,z}
thenqs(2,4) = {x,y}
.
- inline const QList WRAP_ATTR operator+ (unsigned i)
Increments the
QList
byi
. In other words, returns the sliceqs
(i,qs.size())
- inline const QList WRAP_ATTR operator++ () const
Increments the
QList
by1
.
Public Static Functions
- static inline const QList WRAP_ATTR empty_list ()
Returns an empty
QList
.
Friends
- inline friend unsigned long WRAP_ATTR size (const QList &a)
Return the size of the
QList
.
- inline friend const QList WRAP_ATTR operator+ (const QList &a, const QList &b)
Concatenate two
QLists
in sequence. For example,{a,b,c} + {x,y} = {a,b,c,x,y}
- inline friend const QList WRAP_ATTR operator<< (const QList &qs, const unsigned long i)
Returns the first
size()-i
elements ofqs
.Example: If
qs = {a,b,c}
thenqs << 1 = {a,b}
.
- inline friend const QList WRAP_ATTR operator>> (const QList &qs, const unsigned long i)
Returns the last
size()-i
elements ofqs
.Example: If
qs = {a,b,c}
thenqs >> q = {b,c}
.
- inline friend const QList WRAP_ATTR slice (qbit *reg, const unsigned long a, const unsigned long b)
Slice into a
qbit
array.
- inline friend const QList WRAP_ATTR slice (qbit *reg, const int a, const int b)
Slice into a
qbit
array.
- inline friend const QList WRAP_ATTR join (qbit *reg1, qbit *reg2)
Combine two
qbit
arrays.
- inline friend const QList WRAP_ATTR slice (const QList ®, const unsigned long i, const unsigned long j)
Produces a slice of a
QList
, starting from indexi
and ending at indexj-1
.Example: If
qs = {a,b,c,d,e}
thenslice(qs,2,4) = {c,d}
.
- inline friend const QList WRAP_ATTR join (const QList ®1, const QList ®2)
Concatenate two
QLists
in sequence.Example:
join({a,b,c}, {x,y}) = {a,b,c,x,y}
- inline friend std::vector< std::reference_wrapper< qbit > > WRAP_ATTR to_ref_wrappers (QList reg)
Returns a
std::vector
ofstd::ref_wrappers
for the qubits contained in the passedQList
.std::vector<std::ref_wrapper<qbit>>
is used by quantum runtime APIs to specify the qubits on which the API results are returned. As such, this function allows the user to convert a compile-timeQList
into a runtime construct for use by such APIs.- Returns:
std::vector<std::ref_wrapper<qbit>>
-
const QList slice(const QList&, unsigned long, unsigned long)¶
-
namespace qexpr
Quantum Runtime Utilities¶
qrt_errors.hpp
¶
-
namespace iqsdk
Enums
qrt_indexing.hpp
¶
This file defines a class for abstracting away indices into a state space.
A collection of \(n\) qubits has \(2^n\) basis states. We use length \(2^n\) vectors to represent a variety of simulator state spaces and probability vectors. The Quantum State Space Index (QssIndex) class standardizes indexing into such a state vector, and provides features for easily working with indices.
-
namespace iqsdk
Typedefs
-
template<class T>
using QssMap = std::map<QssIndex, T>¶ Use this alias to get a map indexed by QssIndex with appropriate hashing.
A wrapper around a C++ map indexed by a QssIndex, to double or complex. Returned by
getProbabilities()
andgetAmplitudes()
. Useful for holding a state space or partial state space of probabilities (if double) or amplitudes (if complex).
Functions
-
class QssIndex¶
- #include <qrt_indexing.hpp>
Indexes into state spaces returned by SimulatorDevice::getProbabilities() and SimulatorDevice::getAmplitudes()
QssIndex stands for Quantum State Space Index. A state space can be defined with either a
std::vector
or aQssMap
.Public Functions
-
QssIndex()¶
-
QssIndex(size_t num_qubits, size_t idx)¶
Create a state from an integer representation idx.
- Parameters:
idx – Integer representation of the state, counting from the right (little-endian)
-
QssIndex(std::vector<bool> basis)¶
Create a state from a boolean vector representing a state.
QssIndex({true, false}).toStringWithoutKet() == "10"
-
QssIndex(std::string basis)¶
Useful for specifying a state when you want to request data from a large state-space.
- Parameters:
basis – The input string
basis
has the form|b0...bn>
orb0...bn
where eachb
is either 0 or 1 e.g. “|01101>” or “100”.
-
size_t getIndex() const¶
Return the underlying index.
-
size_t getNumQubits() const¶
The number of qubits handled by this state space.
-
std::string toString() const¶
Convert
idx
to a binary representation usingnum_bits
bits, printed in reverse order.This relates the index
idx
into a probability or amplitude vector to its corresponding basis element.
-
inline operator size_t() const¶
-
bool bitAt(size_t i) const¶
Return the value b_i, where
b_i
corresponds to the basis element|b0..bn>
.
-
void setBitAt(size_t i, bool b)¶
If
i
corresponds to the basis elementbi
in|b0..bi..bn>
, changesbi
to correspond to|b0..b..bn>
Public Static Functions
-
static std::vector<QssIndex> patternToIndices(std::string pattern)¶
Given a pattern, produce a vector of
QssIndex
objects obtained by replacingX
,?
, orWildcard
in the pattern by every combination of0
and1
.The patterns
|X1X>
,?1?
and{Wildcard, 1, Wildcard}
all represent the same set of indices:{|010>, |110>, |011>, |111>}
.
Public Static Attributes
-
static const int Wildcard¶
-
QssIndex()¶
-
template<class T>
-
namespace std¶