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 virtual std::map<std::string, std::size_t> measureAllNonCollapsing(std::size_t shots)¶
-
inline char measureOneCollapsing(const dd::Qubit index, const bool assumeProbabilityNormalization = true)¶
-
std::map<std::string, std::size_t> sampleFromAmplitudeVectorInPlace(std::vector<std::complex<dd::fp>> &litudes, std::size_t shots)¶
-
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()¶
-
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¶
-
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)¶
-
std::string exportDDtoGraphvizString(bool colored = true, bool edgeLabels = false, bool classic = false, bool memory = false, bool formatAsPolar = true)¶
Get a GraphViz representation of the currently stored DD.
- Parameters:
colored – Whether to output color-coded edge weights or black and white.
edgeLabels – Whether to output edge labels.
classic – Whether to use the classic visualization or a more modern representation.
memory – An alternative representation for nodes that includes detailed memory information.
formatAsPolar – Whether to format the complex numbers as polar or cartesian coordinates.
- Returns:
A Graphviz program representing the current DD
-
void exportDDtoGraphvizFile(const std::string &filename, bool colored = true, bool edgeLabels = false, bool classic = false, bool memory = false, bool formatAsPolar = true)¶
Write a GraphViz representation of the currently stored DD to a file.
- Parameters:
filename – The name of the file to write to.
colored – Whether to output color-coded edge weights or black and white.
edgeLabels – Whether to output edge labels.
classic – Whether to use the classic visualization or a more modern representation.
memory – An alternative representation for nodes that includes detailed memory information.
formatAsPolar – Whether to format the complex numbers as polar or cartesian coordinates.
Public Members
Public Static Functions
Protected Functions
-
virtual void exportDDtoGraphviz(std::ostream &os, bool colored, bool edgeLabels, bool classic, bool memory, bool formatAsPolar)¶
-
inline explicit Simulator(const std::uint64_t randomSeed)¶