Skip to content

Commit

Permalink
WIP: QHybrid (#461)
Browse files Browse the repository at this point in the history
* QHybrid first draft

* Fix compose

* Fix unit tests

* Optimize thresholdQubits
  • Loading branch information
WrathfulSpatula authored Sep 6, 2020
1 parent f12432b commit 3e910a1
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_library (qrack STATIC
src/bitbuffer.cpp
src/qunit.cpp
src/qpager.cpp
src/qhybrid.cpp
)

add_library (qrack_pinvoke SHARED
Expand Down Expand Up @@ -203,6 +204,7 @@ install (FILES
include/qinterface.hpp
include/qneuron.hpp
include/qpager.hpp
include/qhybrid.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qrack
)

Expand Down
2 changes: 2 additions & 0 deletions include/qengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class QEngine : public QInterface {

virtual void ZeroAmplitudes() = 0;

virtual void CopyStateVec(QInterfacePtr src) = 0;

virtual void GetAmplitudePage(complex* pagePtr, const bitCapInt offset, const bitCapInt length) = 0;
virtual void SetAmplitudePage(const complex* pagePtr, const bitCapInt offset, const bitCapInt length) = 0;
virtual void SetAmplitudePage(
Expand Down
20 changes: 20 additions & 0 deletions include/qengine_cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ class QEngineCPU : virtual public QEngine, public ParallelFor {
engineCpu->runningNorm = ONE_R1;
}

virtual void CopyStateVec(QInterfacePtr src)
{
Finish();
src->Finish();

complex* sv;
if (isSparse) {
sv = new complex[maxQPower];
} else {
sv = std::dynamic_pointer_cast<StateVectorArray>(stateVec)->amplitudes;
}

src->GetQuantumState(sv);

if (isSparse) {
SetQuantumState(sv);
delete[] sv;
}
}

virtual void SetQuantumState(const complex* inputState);
virtual void GetQuantumState(complex* outputState);
virtual void GetProbs(real1* outputProbs);
Expand Down
10 changes: 10 additions & 0 deletions include/qengine_opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ class QEngineOCL : virtual public QEngine {
}
}

virtual void CopyStateVec(QInterfacePtr src)
{
Finish();
src->Finish();

LockSync(CL_MAP_WRITE);
src->GetQuantumState(stateVec);
UnlockSync();
}

virtual void GetAmplitudePage(complex* pagePtr, const bitCapInt offset, const bitCapInt length);
virtual void SetAmplitudePage(const complex* pagePtr, const bitCapInt offset, const bitCapInt length);
virtual void SetAmplitudePage(
Expand Down
7 changes: 7 additions & 0 deletions include/qfactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#if ENABLE_OPENCL
#include "qengine_opencl.hpp"
#include "qhybrid.hpp"
#include "qunitmulti.hpp"
#else
#include "qunit.hpp"
Expand All @@ -41,6 +42,8 @@ QInterfacePtr CreateQuantumInterface(
case QINTERFACE_QUNIT:
return std::make_shared<QUnit>(subengine1, subengine2, args...);
#if ENABLE_OPENCL
case QINTERFACE_HYBRID:
return std::make_shared<QHybrid>(args...);
case QINTERFACE_QUNIT_MULTI:
return std::make_shared<QUnitMulti>(subengine1, args...);
#endif
Expand All @@ -64,6 +67,8 @@ QInterfacePtr CreateQuantumInterface(QInterfaceEngine engine, QInterfaceEngine s
case QINTERFACE_QUNIT:
return std::make_shared<QUnit>(subengine, args...);
#if ENABLE_OPENCL
case QINTERFACE_HYBRID:
return std::make_shared<QHybrid>(args...);
case QINTERFACE_QUNIT_MULTI:
return std::make_shared<QUnitMulti>(subengine, args...);
#endif
Expand All @@ -80,6 +85,8 @@ template <typename... Ts> QInterfacePtr CreateQuantumInterface(QInterfaceEngine
#if ENABLE_OPENCL
case QINTERFACE_OPENCL:
return std::make_shared<QEngineOCL>(args...);
case QINTERFACE_HYBRID:
return std::make_shared<QHybrid>(args...);
#endif
default:
return NULL;
Expand Down
Loading

0 comments on commit 3e910a1

Please sign in to comment.