C++ API Index

The Simulator provides basic functions for the derived simulators to use.

template<class Config = dd::DDPackageConfig>
class Simulator

Public Functions

inline explicit Simulator(const std::uint64_t randomSeed)
inline explicit Simulator()
virtual ~Simulator() = default
virtual std::map<std::string, std::size_t> simulate(std::size_t shots) = 0

Run the simulation in the (derived) class.

Parameters:

shots – number of shots to take from the final quantum state

Returns:

a map from the strings representing basis states to the number of times they have been measured

inline virtual std::map<std::string, std::string> additionalStatistics()
inline std::string measureAll(bool collapse = false)
inline std::map<std::string, std::size_t> measureAllNonCollapsing(std::size_t shots)
inline char measureOneCollapsing(const qc::Qubit index, const bool assumeProbabilityNormalization = true)
std::map<std::string, std::size_t> sampleFromAmplitudeVectorInPlace(std::vector<std::complex<dd::fp>> &amplitudes, std::size_t shots)
std::vector<dd::ComplexValue> getVector() const
std::vector<std::pair<dd::fp, dd::fp>> getVectorPair() const
std::vector<std::complex<dd::fp>> getVectorComplex() const
inline virtual std::size_t getActiveNodeCount() const
inline virtual std::size_t getMaxNodeCount() const
inline virtual std::size_t getMaxMatrixNodeCount() const
inline virtual std::size_t getMatrixActiveNodeCount() const
inline virtual std::size_t countNodesFromRoot()
std::pair<dd::ComplexValue, std::string> getPathOfLeastResistance() const
inline std::string getSeed() const
virtual std::size_t getNumberOfQubits() const = 0
virtual std::size_t getNumberOfOps() const = 0
virtual std::string getName() const = 0
inline void setTolerance(const dd::fp tolerance)
inline dd::fp getTolerance() const
std::vector<std::priority_queue<std::pair<double, dd::vNode*>, std::vector<std::pair<double, dd::vNode*>>>> getNodeContributions(const dd::vEdge &edge) const

Calculate the contributions of each node and return as vector of priority queues (each queue corresponds to a level in the decision diagram)

Template Parameters:

Config – Configuration for the underlying DD package

Parameters:

edge – root edge to the decision diagram

Returns:

vector of priority queues with each queue corresponding to a level of the decision diagram

double approximateByFidelity(std::unique_ptr<dd::Package<Config>> &localDD, dd::vEdge &edge, double targetFidelity, bool allLevels, bool actuallyRemoveNodes, bool verbose = false)

Approximate a quantum state to a given fidelity.

Template Parameters:

Config – Configuration for the underlying DD package

Parameters:
  • localDD – pointer to the DD package where the quantum state lives

  • edge – reference to the root node of the quantum state, will point to the new state afterwards if removeNodes is true

  • targetFidelity – the fidelity that should be achieved

  • allLevels – if true, apply approximation to targetFidely to each level, if false, only apply to the most suitable level

  • actuallyRemoveNodes – if true, actually remove the nodes that are identified as unnecessary for the targetFidelity, if false, don’t remove anything

  • verbose – output information about the process and result

Returns:

fidelity of the resulting quantum state

inline double approximateByFidelity(double targetFidelity, bool allLevels, bool removeNodes, bool verbose = false)
double approximateBySampling(std::unique_ptr<dd::Package<Config>> &localDD, dd::vEdge &edge, std::size_t nSamples, std::size_t threshold, bool actuallyRemoveNodes, bool verbose = false)
inline double approximateBySampling(std::size_t nSamples, std::size_t threshold, bool removeNodes, bool verbose = false)

Public Members

std::unique_ptr<dd::Package<Config>> dd = std::make_unique<dd::Package<Config>>()
dd::vEdge rootEdge = {}

Public Static Functions

static inline std::string toBinaryString(const std::size_t value, const std::size_t numberOfQubits)
static dd::vEdge removeNodes(std::unique_ptr<dd::Package<Config>> &localDD, dd::vEdge edge, std::map<dd::vNode*, dd::vEdge> &dagEdges)

Protected Attributes

std::mt19937_64 mt
std::uint64_t seed = 0
bool hasFixedSeed
dd::fp epsilon = 0.001

Protected Static Functions

static void nextPath(std::string &s)