Commit aefa8f51 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Major repository restructure. quantum is now the quantum runtime package,...

Major repository restructure. quantum is now the quantum runtime package, moved rigetti, simple acc, and scaffold to impls dir
parent 9e85699c
......@@ -28,16 +28,15 @@
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#ifndef QUANTUM_GATE_ACCELERATORS_EIGENACCELERATOR_HPP_
#define QUANTUM_GATE_ACCELERATORS_EIGENACCELERATOR_HPP_
#ifndef QUANTUM_GATE_ACCELERATORS_SIMPLEACCELERATOR_HPP_
#define QUANTUM_GATE_ACCELERATORS_SIMPLEACCELERATOR_HPP_
#include <boost/dll/alias.hpp>
#include "QPUGate.hpp"
#include "SimulatedQubits.hpp"
#include "Accelerator.hpp"
#include "InstructionIterator.hpp"
#include "FunctionalGateInstructionVisitor.hpp"
#include <random>
#include "FunctionalGateInstructionVisitor.hpp"
#include "SimulatedQubits.hpp"
namespace xacc {
namespace quantum {
......@@ -47,13 +46,13 @@ using ProductList = std::vector<fire::Tensor<2, fire::EigenProvider, std::comple
using ComplexTensor = fire::Tensor<2, fire::EigenProvider, std::complex<double>>;
/**
* The FireTensorAccelerator is an XACC Accelerator that simulates
* The SimpleTensorAccelerator is an XACC Accelerator that simulates
* gate based quantum computing circuits. It models the QPUGate Accelerator
* with SimulatedQubit AcceleratorBuffer. It relies on the Fire Scientific Computing
* Framework's tensor module to model a specific set of quantum gates. It uses these
* tensors to build up the unitary matrix described by the circuit.
*/
class FireTensorAccelerator : virtual public QPUGate {
class SimpleAccelerator : virtual public Accelerator {
public:
/**
......@@ -95,23 +94,41 @@ public:
*/
virtual void execute(std::shared_ptr<AcceleratorBuffer> buffer, const std::shared_ptr<xacc::Function> kernel);
/**
* This Accelerator models QPU Gate accelerators.
* @return
*/
virtual AcceleratorType getType() {
return AcceleratorType::qpu_gate;
}
/**
* We have no need to transform the IR for this Accelerator,
* so return an empty list
* @return
*/
virtual std::vector<xacc::IRTransformation> getIRTransformations() {
std::vector<xacc::IRTransformation> v;
return v;
}
/**
* Register this Accelerator with the framework.
*/
static void registerAccelerator() {
xacc::RegisterAccelerator<xacc::quantum::FireTensorAccelerator> FIRETEMP(
"firetensor");
xacc::RegisterAccelerator<xacc::quantum::SimpleAccelerator> SIMPLETEMP(
"simple");
}
/**
* The destructor
*/
virtual ~FireTensorAccelerator() {}
virtual ~SimpleAccelerator() {}
};
// Create an alias to search for.
RegisterAccelerator(xacc::quantum::FireTensorAccelerator)
RegisterAccelerator(xacc::quantum::SimpleAccelerator)
}
}
......
......@@ -156,13 +156,13 @@ public:
stream
<< std::bitset<TotalNumberOfQubits>(i).to_string().substr(
TotalNumberOfQubits - size(), TotalNumberOfQubits) << " -> "
<< bufferState(i) << "\n";
<< std::fabs(bufferState(i)) << "\n";
}
} else {
for (int i = 0; i < bufferState.dimension(0); i++) {
stream << std::bitset<TotalNumberOfQubits>(i).to_string()
<< " -> " << bufferState(i) << "\n";
<< " -> " << std::fabs(bufferState(i)) << "\n";
}
}
}
......@@ -174,14 +174,14 @@ public:
std::bitset<TotalNumberOfQubits>(i).to_string().substr(
TotalNumberOfQubits - size(),
TotalNumberOfQubits) + " -> "
+ std::to_string(std::real(bufferState(i))));
+ std::to_string(std::real(std::fabs(bufferState(i)))));
}
} else {
for (int i = 0; i < bufferState.dimension(0); i++) {
XACCInfo(
std::bitset<TotalNumberOfQubits>(i).to_string() + " -> "
+ std::to_string(std::real(bufferState(i))));
+ std::to_string(std::real(std::fabs(bufferState(i)))));
}
}
}
......
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
......@@ -29,17 +30,17 @@
*
**********************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE FireTensorAcceleratorTester
#define BOOST_TEST_MODULE SimpleAcceleratorTester
#include <memory>
#include <boost/test/included/unit_test.hpp>
#include "FireTensorAccelerator.hpp"
#include "SimpleAccelerator.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkKernelExecution) {
FireTensorAccelerator acc;
SimpleAccelerator acc;
auto qreg1 = acc.createBuffer("qreg", 3);
auto f = std::make_shared<GateFunction>("foo");
......
/***********************************************************************************
* Copyright (c) 2016, UT-Battelle
* All rights reserved.
......@@ -32,7 +33,7 @@
#define BOOST_TEST_MODULE QubitsTester
#include <boost/test/included/unit_test.hpp>
#include "SimulatedQubits.hpp"
#include "../../simple-simulator/SimulatedQubits.hpp"
using namespace xacc::quantum;
......
......@@ -31,11 +31,8 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gateqir)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gateqir/instructions)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gateqir/functions)
add_subdirectory(gateqir)
add_subdirectory(compilers)
add_subdirectory(accelerators)
add_subdirectory(utils)
#***********************************************************************************
# Copyright (c) 2016, UT-Battelle
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the xacc nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Contributors:
# Initial API and implementation - Alex McCaskey
#
#**********************************************************************************/
add_subdirectory(firetensoraccelerator)
add_subdirectory(rigetti)
/***********************************************************************************
* Copyright (c) 2016, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#ifndef QUANTUM_GATE_ACCELERATORS_QPUGATE_HPP_
#define QUANTUM_GATE_ACCELERATORS_QPUGATE_HPP_
#include "Accelerator.hpp"
namespace xacc {
namespace quantum {
/**
*
*/
//template<typename BitsType>
class QPUGate: virtual public Accelerator {
public:
/**
* This Accelerator models QPU Gate accelerators.
* @return
*/
virtual AcceleratorType getType() {
return AcceleratorType::qpu_gate;
}
/**
* We have no need to transform the IR for this Accelerator,
* so return an empty list
* @return
*/
virtual std::vector<xacc::IRTransformation> getIRTransformations() {
std::vector<xacc::IRTransformation> v;
return v;
}
virtual ~QPUGate() {}
};
}
}
#endif
......@@ -124,20 +124,6 @@ public:
DEFINE_VISITABLE()
// virtual void serializeJson(PrettyWriter<StringBuffer> writer) {
// writer.StartObject();
// writer.String("gate");
// writer.String(gateName.c_str());
// writer.String("enabled");
// writer.Bool(enabled);
// writer.String("qubits");
// writer.StartArray();
// for (auto qi : bits()) {
// writer.Int(qi);
// }
// writer.EndArray();
// writer.EndObject();
// }
/**
* The destructor
......@@ -146,6 +132,76 @@ public:
}
};
/**
* The ParamaterizedGateInstruction is a GateInstruction that is
* templated on a list of variadic parameters that model the
* instructions gate parameters. For example, this class could be
* subclassed to provide a rotation gate with an angle theta
* (ParamaterizedGateInstruction<double>).
*/
template<typename ... InstructionParameter>
class ParameterizedGateInstruction: public virtual GateInstruction {
protected:
/**
* The paramaters that this gate instruction requires.
*/
std::tuple<InstructionParameter...> params;
public:
/**
* The constructor, takes the parameters
* @param pars
*/
ParameterizedGateInstruction(InstructionParameter ... pars) :
params(std::make_tuple(pars...)), GateInstruction(std::vector<int>{}) {
}
/**
* Return the gate parameter at the given index.
*
* @param idx
* @return
*/
auto getParameter(const std::size_t idx) {
if (idx + 1 > sizeof...(InstructionParameter)) {
XACCError("Invalid Parameter requested from Parameterized Gate Instruction.");
}
return xacc::tuple_runtime_get(params, idx);
}
/**
* Return an assembly-like string representation for this
* instruction.
*
* @param bufferVarName
* @return
*/
virtual const std::string toString(const std::string& bufferVarName) {
auto str = gateName;
str += "(";
xacc::tuple_for_each(params, [&](auto element) {
str += std::to_string(element) + ",";
});
str = str.substr(0, str.length() - 1) + ") ";
for (auto q : bits()) {
str += bufferVarName + std::to_string(q) + ",";
}
// Remove trailing comma
str = str.substr(0, str.length() - 1);
return str;
}
DEFINE_VISITABLE()
};
/**
*/
using GateInstructionRegistry = Registry<GateInstruction, std::vector<int>>;
......@@ -164,6 +220,28 @@ public:
}));
}
};
/**
*/
template<typename ... Params>
using ParameterizedGateInstructionRegistry = Registry<ParameterizedGateInstruction<Params...>, std::vector<int>, Params...>;
/**
*/
template<typename T, typename ... Params>
class RegisterParameterizedGateInstruction {
public:
RegisterParameterizedGateInstruction(const std::string& name) {
ParameterizedGateInstructionRegistry<Params...>::instance()->add(name,
(std::function<
std::shared_ptr<
xacc::quantum::ParameterizedGateInstruction<
Params...>>(std::vector<int>, Params...)>) ([](std::vector<int> qubits, Params... args) {
return std::make_shared<T>(qubits, args...);
}));
}
};
}
}
......
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#ifndef QUANTUM_GATE_GATEQIR_PARAMETERIZEDGATEINSTRUCTION_HPP_
#define QUANTUM_GATE_GATEQIR_PARAMETERIZEDGATEINSTRUCTION_HPP_
#include "Utils.hpp"
#include "GateInstruction.hpp"
namespace xacc {
namespace quantum {
/**
* The ParamaterizedGateInstruction is a GateInstruction that is
* templated on a list of variadic parameters that model the
* instructions gate parameters. For example, this class could be
* subclassed to provide a rotation gate with an angle theta
* (ParamaterizedGateInstruction<double>).
*/
template<typename ... InstructionParameter>
class ParameterizedGateInstruction: public virtual GateInstruction {
protected:
/**
* The paramaters that this gate instruction requires.
*/
std::tuple<InstructionParameter...> params;
public:
/**
* The constructor, takes the parameters
* @param pars
*/
ParameterizedGateInstruction(InstructionParameter ... pars) :
params(std::make_tuple(pars...)), GateInstruction(std::vector<int>{}) {
}
/**
* Return the gate parameter at the given index.
*
* @param idx
* @return
*/
auto getParameter(const std::size_t idx) {
if (idx + 1 > sizeof...(InstructionParameter)) {
XACCError("Invalid Parameter requested from Parameterized Gate Instruction.");
}
return xacc::tuple_runtime_get(params, idx);
}
/**
* Return an assembly-like string representation for this
* instruction.
*
* @param bufferVarName
* @return
*/
virtual const std::string toString(const std::string& bufferVarName) {
auto str = gateName;
str += "(";
xacc::tuple_for_each(params, [&](auto element) {
str += std::to_string(element) + ",";
});
str = str.substr(0, str.length() - 1) + ") ";
for (auto q : bits()) {
str += bufferVarName + std::to_string(q) + ",";
}
// Remove trailing comma
str = str.substr(0, str.length() - 1);
return str;
}
DEFINE_VISITABLE()
};
/**
*/
template<typename ... Params>
using ParameterizedGateInstructionRegistry = Registry<ParameterizedGateInstruction<Params...>, std::vector<int>, Params...>;
/**
*/
template<typename T, typename ... Params>
class RegisterParameterizedGateInstruction {
public:
RegisterParameterizedGateInstruction(const std::string& name) {
ParameterizedGateInstructionRegistry<Params...>::instance()->add(name,
(std::function<
std::shared_ptr<
xacc::quantum::ParameterizedGateInstruction<
Params...>>(std::vector<int>, Params...)>) ([](std::vector<int> qubits, Params... args) {
return std::make_shared<T>(qubits, args...);
}));
}
};
}
}
#endif
......@@ -31,7 +31,7 @@
#ifndef QUANTUM_GATE_IR_MEASURE_HPP_
#define QUANTUM_GATE_IR_MEASURE_HPP_
#include "ParameterizedGateInstruction.hpp"
#include "GateInstruction.hpp"
namespace xacc {
namespace quantum {
......
......@@ -31,7 +31,7 @@
#ifndef QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RZ_HPP_
#define QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RZ_HPP_
#include "ParameterizedGateInstruction.hpp"
#include "GateInstruction.hpp"
namespace xacc {
namespace quantum {
......
......@@ -30,7 +30,6 @@
**********************************************************************************/
#include "GateFunction.hpp"
#include "GateInstruction.hpp"
#include "ParameterizedGateInstruction.hpp"
#include <boost/program_options.hpp>
#include <iostream>
#include <fstream>
......
Supports Markdown
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