Newer
Older

Mccaskey, Alex
committed
#ifndef QUANTUM_GATE_QUBITS_HPP_
#define QUANTUM_GATE_QUBITS_HPP_
#include "Accelerator.hpp"
#include <complex>

Mccaskey, Alex
committed
#include <Eigen/Dense>

Mccaskey, Alex
committed
namespace xacc {
namespace quantum {

Mccaskey, Alex
committed
using QubitState = Eigen::VectorXcd;

Mccaskey, Alex
committed
/**
*
*/
template<const int NumberOfQubits>
class Qubits: public AcceleratorBits<NumberOfQubits> {

Mccaskey, Alex
committed
protected:

Mccaskey, Alex
committed
QubitState state;
public:

Mccaskey, Alex
committed
Qubits() :
state((int) std::pow(2, NumberOfQubits)) {
// Initialize to |000...000> state
state.setZero();
state(0) = 1.0;

Mccaskey, Alex
committed
}

Mccaskey, Alex
committed

Mccaskey, Alex
committed
void applyUnitary(Eigen::MatrixXcd& U) {
state = U * state;

Mccaskey, Alex
committed
}
QubitState& getState() {
return state;
}
void setState(QubitState& st) {
state = st;
}

Mccaskey, Alex
committed
void printState(std::ostream& stream) {
for (int i = 0; i < state.rows(); i++) {
stream << std::bitset<NumberOfQubits>(i).to_string() << " -> " << state(i) << "\n";
}

Mccaskey, Alex
committed
}
};