Qrack  9.13
General classical-emulating-quantum development framework
qbdt_node.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017-2023. All rights reserved.
4 //
5 // QBinaryDecision tree is an alternative approach to quantum state representation, as
6 // opposed to state vector representation. This is a compressed form that can be
7 // operated directly on while compressed. Inspiration for the Qrack implementation was
8 // taken from JKQ DDSIM, maintained by the Institute for Integrated Circuits at the
9 // Johannes Kepler University Linz:
10 //
11 // https://github.com/iic-jku/ddsim
12 //
13 // Licensed under the GNU Lesser General Public License V3.
14 // See LICENSE.md in the project root or https://www.gnu.org/licenses/lgpl-3.0.en.html
15 // for details.
16 
17 #pragma once
18 
19 #include "qbdt_node_interface.hpp"
20 
21 namespace Qrack {
22 
23 class QBdtNode;
24 typedef std::shared_ptr<QBdtNode> QBdtNodePtr;
25 
26 class QBdtNode : public QBdtNodeInterface {
27 protected:
28 #if ENABLE_QBDT_CPU_PARALLEL && ENABLE_PTHREAD
29 #if ENABLE_COMPLEX_X2
30  virtual void PushStateVector(const complex2& mtrxCol1, const complex2& mtrxCol2, const complex2& mtrxColShuff1,
31  const complex2& mtrxColShuff2, QBdtNodeInterfacePtr& b0, QBdtNodeInterfacePtr& b1, bitLenInt depth,
32  bitLenInt parDepth = 1U);
33 #else
34  virtual void PushStateVector(const complex* mtrx, QBdtNodeInterfacePtr& b0, QBdtNodeInterfacePtr& b1,
35  bitLenInt depth, bitLenInt parDepth = 1U);
36 #endif
37 #else
38 #if ENABLE_COMPLEX_X2
39  virtual void PushStateVector(const complex2& mtrxCol1, const complex2& mtrxCol2, const complex2& mtrxColShuff1,
40  const complex2& mtrxColShuff2, QBdtNodeInterfacePtr& b0, QBdtNodeInterfacePtr& b1, bitLenInt depth);
41 #else
42  virtual void PushStateVector(
43  const complex* mtrx, QBdtNodeInterfacePtr& b0, QBdtNodeInterfacePtr& b1, bitLenInt depth);
44 #endif
45 #endif
46 
47 public:
50  {
51  // Intentionally left blank
52  }
53 
54  QBdtNode(const complex& scl)
55  : QBdtNodeInterface(scl)
56  {
57  // Intentionally left blank
58  }
59 
61  : QBdtNodeInterface(scl, b)
62  {
63  // Intentionally left blank
64  }
65 
66  virtual ~QBdtNode()
67  {
68  // Virtual destructor for inheritance
69  }
70 
71  virtual QBdtNodeInterfacePtr ShallowClone() { return std::make_shared<QBdtNode>(scale, branches); }
72 
73 #if ENABLE_QBDT_CPU_PARALLEL && ENABLE_PTHREAD
74  virtual void InsertAtDepth(QBdtNodeInterfacePtr b, bitLenInt depth, const bitLenInt& size, bitLenInt parDepth = 1U);
75 #else
76  virtual void InsertAtDepth(QBdtNodeInterfacePtr b, bitLenInt depth, const bitLenInt& size);
77 #endif
78 
79 #if ENABLE_QBDT_CPU_PARALLEL && ENABLE_PTHREAD
80  virtual void PopStateVector(bitLenInt depth = 1U, bitLenInt parDepth = 1U);
81 #else
82  virtual void PopStateVector(bitLenInt depth = 1U);
83 #endif
84 
85 #if ENABLE_QBDT_CPU_PARALLEL && ENABLE_PTHREAD
86  virtual void Branch(bitLenInt depth = 1U, bitLenInt parDeth = 1U);
87 #else
88  virtual void Branch(bitLenInt depth = 1U);
89 #endif
90 
91 #if ENABLE_QBDT_CPU_PARALLEL && ENABLE_PTHREAD
92  virtual void Prune(bitLenInt depth = 1U, bitLenInt parDepth = 1U);
93 #else
94  virtual void Prune(bitLenInt depth = 1U);
95 #endif
96 
97  virtual void Normalize(bitLenInt depth = 1U);
98 
99 #if ENABLE_COMPLEX_X2
100  virtual void Apply2x2(const complex2& mtrxCol1, const complex2& mtrxCol2, const complex2& mtrxColShuff1,
101  const complex2& mtrxColShuff2, bitLenInt depth);
102 #else
103  virtual void Apply2x2(const complex* mtrx, bitLenInt depth);
104 #endif
105 };
106 
107 } // namespace Qrack
Definition: qbdt_node_interface.hpp:36
QBdtNodeInterfacePtr branches[2U]
Definition: qbdt_node_interface.hpp:66
complex scale
Definition: qbdt_node_interface.hpp:65
Definition: qbdt_node.hpp:26
virtual void Apply2x2(const complex *mtrx, bitLenInt depth)
Definition: node.cpp:764
virtual void PushStateVector(const complex *mtrx, QBdtNodeInterfacePtr &b0, QBdtNodeInterfacePtr &b1, bitLenInt depth)
Definition: node.cpp:826
virtual void Normalize(bitLenInt depth=1U)
Definition: node.cpp:290
virtual void Prune(bitLenInt depth=1U)
Definition: node.cpp:42
QBdtNode(const complex &scl)
Definition: qbdt_node.hpp:54
virtual QBdtNodeInterfacePtr ShallowClone()
Definition: qbdt_node.hpp:71
virtual void PopStateVector(bitLenInt depth=1U)
Definition: node.cpp:331
QBdtNode()
Definition: qbdt_node.hpp:48
virtual void Branch(bitLenInt depth=1U)
Definition: node.cpp:221
QBdtNode(const complex &scl, QBdtNodeInterfacePtr *b)
Definition: qbdt_node.hpp:60
virtual ~QBdtNode()
Definition: qbdt_node.hpp:66
virtual void InsertAtDepth(QBdtNodeInterfacePtr b, bitLenInt depth, const bitLenInt &size)
Definition: node.cpp:422
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
std::shared_ptr< QBdtNode > QBdtNodePtr
Definition: qbdt_node.hpp:23
std::complex< real1 > complex
Definition: qrack_types.hpp:128
std::shared_ptr< QBdtNodeInterface > QBdtNodeInterfacePtr
Definition: qbdt_node_interface.hpp:33
#define bitLenInt
Definition: qrack_types.hpp:38
SIMD implementation of the double precision complex vector type of 2 complex numbers,...
Definition: complex16x2simd.hpp:30