Commit b88d2532 authored by Daniel Strano's avatar Daniel Strano
Browse files

Update Qrack plugin for v7 API


Signed-off-by: default avatarDaniel Strano <stranoj@gmail.com>
parent c3faf15a
......@@ -50,6 +50,26 @@ namespace quantum {
m_use_stabilizer = params.get<bool>("use_stabilizer");
}
if (params.keyExists<bool>("use_binary_decision_tree"))
{
m_use_binary_decision_tree = params.get<bool>("use_binary_decision_tree");
}
if (params.keyExists<bool>("use_paging"))
{
m_use_paging = params.get<bool>("use_paging");
}
if (params.keyExists<bool>("use_z_x_fusion"))
{
m_use_z_x_fusion = params.get<bool>("use_z_x_fusion");
}
if (params.keyExists<bool>("use_cpu_gpu_hybrid"))
{
m_use_cpu_gpu_hybrid = params.get<bool>("use_cpu_gpu_hybrid");
}
if (params.keyExists<int>("device_id"))
{
m_device_id = params.get<int>("device_id");
......@@ -111,7 +131,7 @@ namespace quantum {
}
const auto runCircuit = [&](int shots){
m_visitor->initialize(buffer, shots, m_use_opencl, m_use_qunit, m_use_opencl_multi, m_use_stabilizer, m_device_id, m_do_normalize, m_zero_threshold);
m_visitor->initialize(buffer, shots, m_use_opencl, m_use_qunit, m_use_opencl_multi, m_use_stabilizer, m_use_binary_decision_tree, m_use_paging, m_use_z_x_fusion, m_use_cpu_gpu_hybrid, m_device_id, m_do_normalize, m_zero_threshold);
// Walk the IR tree, and visit each node
InstructionIterator it(compositeInstruction);
......
......@@ -39,8 +39,12 @@ private:
int m_shots = -1;
bool m_use_opencl = true;
bool m_use_qunit = true;
bool m_use_opencl_multi = false;
bool m_use_opencl_multi = true;
bool m_use_stabilizer = true;
bool m_use_binary_decision_tree = false;
bool m_use_paging = true;
bool m_use_z_x_fusion = true;
bool m_use_cpu_gpu_hybrid = true;
int m_device_id = -1;
bool m_do_normalize = false;
double m_zero_threshold = REAL1_EPSILON;
......
......@@ -15,26 +15,53 @@
#include "QrackVisitor.hpp"
#include "xacc.hpp"
#define MAKE_ENGINE(num_qubits, perm) Qrack::CreateQuantumInterface(qIType1, qIType2, qIType3, num_qubits, perm, nullptr, Qrack::CMPLX_DEFAULT_ARG, doNormalize, false, false, device_id, true, zero_threshold)
#define MAKE_ENGINE(num_qubits, perm) Qrack::CreateQuantumInterface(simulatorType, num_qubits, perm, nullptr, Qrack::CMPLX_DEFAULT_ARG, doNormalize, false, false, device_id, true, zero_threshold)
namespace xacc {
namespace quantum {
void QrackVisitor::initialize(std::shared_ptr<AcceleratorBuffer> buffer, int shots, bool use_opencl, bool use_qunit, bool use_opencl_multi, bool use_stabilizer, int device_id, bool doNormalize, double zero_threshold)
void QrackVisitor::initialize(std::shared_ptr<AcceleratorBuffer> buffer, int shots, bool use_opencl, bool use_qunit, bool use_opencl_multi, bool use_stabilizer, bool use_binary_decision_tree, bool use_paging, bool use_z_x_fusion, bool use_cpu_gpu_hybrid, int device_id, bool doNormalize, double zero_threshold)
{
m_buffer = std::move(buffer);
m_measureBits.clear();
m_shots = shots;
m_shotsMode = shots > 1;
Qrack::QInterfaceEngine qIType1, qIType2, qIType3;
#if ENABLE_OPENCL
bool isOcl = use_opencl && (Qrack::OCLEngine::Instance()->GetDeviceCount() > 0);
bool isOclMulti = use_opencl_multi && (Qrack::OCLEngine::Instance()->GetDeviceCount() > 1);
#else
bool isOcl = false;
bool isOclMulti = false;
#endif
std::vector<Qrack::QInterfaceEngine> simulatorType;
if (use_qunit) {
qIType1 = use_opencl_multi ? Qrack::QINTERFACE_QUNIT_MULTI : Qrack::QINTERFACE_QUNIT;
qIType2 = use_stabilizer ? Qrack::QINTERFACE_STABILIZER_HYBRID : (use_opencl ? Qrack::QINTERFACE_OPTIMAL_SCHROEDINGER : Qrack::QINTERFACE_CPU);
qIType3 = use_opencl ? (use_stabilizer ? Qrack::QINTERFACE_OPTIMAL_SCHROEDINGER : Qrack::QINTERFACE_OPTIMAL_SINGLE_PAGE ) : Qrack::QINTERFACE_CPU;
} else {
qIType1 = use_stabilizer ? Qrack::QINTERFACE_STABILIZER_HYBRID : (use_opencl ? Qrack::QINTERFACE_OPTIMAL_SCHROEDINGER : Qrack::QINTERFACE_CPU);
qIType2 = use_opencl ? (use_stabilizer ? Qrack::QINTERFACE_OPTIMAL_SCHROEDINGER : Qrack::QINTERFACE_OPTIMAL_SINGLE_PAGE) : Qrack::QINTERFACE_CPU;
qIType3 = Qrack::QINTERFACE_OPTIMAL_SINGLE_PAGE;
simulatorType.push_back(isOclMulti ? Qrack::QINTERFACE_QUNIT_MULTI : Qrack::QINTERFACE_QUNIT);
}
if (use_stabilizer) {
simulatorType.push_back(Qrack::QINTERFACE_STABILIZER_HYBRID);
}
if (use_binary_decision_tree) {
simulatorType.push_back(Qrack::QINTERFACE_BDT);
}
if (use_paging) {
simulatorType.push_back(Qrack::QINTERFACE_QPAGER);
}
if (use_z_x_fusion) {
simulatorType.push_back(Qrack::QINTERFACE_MASK_FUSION);
}
if (isOcl && use_cpu_gpu_hybrid) {
simulatorType.push_back(Qrack::QINTERFACE_HYBRID);
}
if (!simulatorType.size()) {
simulatorType.push_back(isOcl ? Qrack::QINTERFACE_OPENCL : Qrack::QINTERFACE_CPU);
}
m_qReg = MAKE_ENGINE(m_buffer->size(), 0);
......
......@@ -34,7 +34,7 @@ namespace xacc {
namespace quantum {
class QrackVisitor : public AllGateVisitor, public OptionsProvider, public xacc::Cloneable<QrackVisitor> {
public:
void initialize(std::shared_ptr<AcceleratorBuffer> buffer, int shots, bool use_opencl, bool use_qunit, bool use_opencl_multi, bool use_stabilizer, int device_id, bool doNormalize, double zero_threshold);
void initialize(std::shared_ptr<AcceleratorBuffer> buffer, int shots, bool use_opencl, bool use_qunit, bool use_opencl_multi, bool use_stabilizer, bool use_binary_decision_tree, bool use_paging, bool use_z_x_fusion, bool use_cpu_gpu_hybrid, int device_id, bool doNormalize, double zero_threshold);
void finalize();
void visit(Hadamard& h) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment