SimpleAccelerator.hpp 4.17 KB
Newer Older
1
/***********************************************************************************
2
 * Copyright (c) 2017, UT-Battelle
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * 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
 *
 **********************************************************************************/
31
32
#ifndef QUANTUM_GATE_ACCELERATORS_SIMPLEACCELERATOR_HPP_
#define QUANTUM_GATE_ACCELERATORS_SIMPLEACCELERATOR_HPP_
33

34
#include "Accelerator.hpp"
35
#include "InstructionIterator.hpp"
36
#include <random>
37
38
#include "FunctionalGateInstructionVisitor.hpp"
#include "SimulatedQubits.hpp"
39

40
41
42
43
namespace xacc {
namespace quantum {

/**
44
 * The SimpleTensorAccelerator is an XACC Accelerator that simulates
45
46
47
48
 * 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.
49
 */
50
class SimpleAccelerator : virtual public Accelerator {
51
52
public:

53
54
55
56
57
58
59
60
61
62
	/**
	 * Create, store, and return an AcceleratorBuffer with the given
	 * variable id string and of the given number of bits.
	 * The string id serves as a unique identifier
	 * for future lookups and reuse of the AcceleratorBuffer.
	 *
	 * @param varId
	 * @param size
	 * @return
	 */
63
	std::shared_ptr<AcceleratorBuffer> createBuffer(const std::string& varId,
64
			const int size);
65

66
67
68
69
70
71
72
	virtual void initialize() {

	}

	virtual std::shared_ptr<AcceleratorBuffer> createBuffer(
				const std::string& varId);

73
	/**
74
75
76
77
	 * Return true if this Accelerator can allocated
	 * NBits number of bits.
	 * @param NBits
	 * @return
78
	 */
79
	virtual bool isValidBufferSize(const int NBits);
80

81
	/**
82
	 * Execute the simulation. Requires both a valid SimulatedQubits buffer and
83
	 * XACC IR Function instance modeling the quantum circuit.
84
85
86
	 *
	 * @param ir
	 */
87
	virtual void execute(std::shared_ptr<AcceleratorBuffer> buffer, const std::shared_ptr<xacc::Function> kernel);
88

89
90
91
92
93
94
95
96
97
98
99
100
101
	/**
	 * 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
	 */
102
103
	virtual std::vector<std::shared_ptr<IRTransformation>> getIRTransformations() {
		std::vector<std::shared_ptr<IRTransformation>> v;
104
105
106
		return v;
	}

Mccaskey, Alex's avatar
Mccaskey, Alex committed
107
108
109
110
111
112
113
114
115
	virtual const std::string name() const {
		return "simple";
	}

	virtual const std::string description() const {
		return "The Simple Accelerator simply builds up the unitary matrix "
				"associated with the IR to be executed and operates on a state vector.";
	}

116
117
118
	/**
	 * The destructor
	 */
119
	virtual ~SimpleAccelerator() {}
120
121

};
122

123
}
124
125
126
127
}



128

129
#endif