DWQMI.hpp 5.1 KB
Newer Older
1
2
3
4
5
6
7
8
/*******************************************************************************
 * Copyright (c) 2017 UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompanies this
 * distribution. The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
 * is available at https://eclipse.org/org/documents/edl-v10.php
9
10
 *
 * Contributors:
11
12
 *   Alexander J. McCaskey - initial API and implementation
 *******************************************************************************/
13
14
15
16
17
18
19
20
21
#ifndef QUANTUM_AQC_IR_DWQMI_HPP_
#define QUANTUM_AQC_IR_DWQMI_HPP_

#include "Instruction.hpp"

namespace xacc {

namespace quantum {

22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * The DWQMI (D=Wave Quantum Machine Instruction) class is an XACC
 * Instruction that models a logical problem or hardware bias or
 * connection for an optimization problem to be solved on
 * the D-Wave QPU. It keeps track of 2 bits indices, if both
 * are the same index then this DWQMI Instruction models
 * a bias value, and if they are different indices,
 * then this Instruction models a logical coupling.
 *
 * Note that this class can model both problem bias/couplings and
 * hardware bias/couplings. The hardware bias/couplings result from
 * a minor graph embedding computation.
 *
 */
36
class DWQMI: public Instruction {
37
38
39

protected:

40
41
42
	/**
	 * The qubits involved in this Instruction
	 */
43
44
	std::vector<int> qubits;

45
46
47
	/**
	 * The bias or coupling value.
	 */
48
49
	InstructionParameter parameter;

50
51
52
53
	/**
	 * Is this Instruction enabled or disabled.
	 *
	 */
54
	bool enabled = true;
55

56
57
public:

58
59
60
61
62
63
	/**
	 * The Constructor, takes one qubit
	 * indicating this is a bias value, initialized to 0.0
	 *
	 * @param qbit The bit index
	 */
64
65
66
	DWQMI(int qbit) :
			qubits(std::vector<int> { qbit, qbit }), parameter(0.0) {
	}
67

68
69
70
71
72
73
74
75
	/**
	 * The Constructor, takes one qubit
	 * indicating this is a bias value, but
	 * set to the provided bias.
	 *
	 * @param qbit The bit index
	 * @param param The bias value
	 */
76
77
78
	DWQMI(int qbit, double param) :
			qubits(std::vector<int> { qbit, qbit }), parameter(param) {
	}
79

80
81
82
83
84
85
86
87
88
	/**
	 * The Constructor, takes two qubit indices
	 * to indicate that this is a coupler, with
	 * value given by the provided parameter.
	 *
	 * @param qbit1 The bit index
	 * @param qbit2 The bit index
	 * @param param The coupling weight
	 */
89
90
91
	DWQMI(int qbit1, int qbit2, double param) :
			qubits(std::vector<int> { qbit1, qbit2 }), parameter(param) {
	}
92
93
94
95
96
97

	/**
	 * Return the name of this Instruction
	 *
	 * @return name The name of this Instruction
	 */
98
	virtual const std::string name() const {
99
		return "dw-qmi";
100
	}
101
102
103
	 virtual const std::string description() const {
		 return "";
	 }
104
105
106
	virtual const std::string getTag() {
		return "";
	}
107

108
109
110
	virtual void mapBits(std::vector<int> bitMap) {
	}

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	/**
	 * Persist this Instruction to an assembly-like
	 * string.
	 *
	 * @param bufferVarName The name of the AcceleratorBuffer
	 * @return str The assembly-like string.
	 */
	virtual const std::string toString(const std::string& bufferVarName) {
		std::stringstream ss;
		ss << bits()[0] << " " << bits()[1] << " " << getParameter(0);
		return ss.str();
	}

	/**
	 * Return the indices of the bits that this Instruction
	 * operates on.
	 *
	 * @return bits The bits this Instruction operates on.
	 */
	virtual const std::vector<int> bits() {
		return qubits;
	}

	/**
	 * Return this Instruction's parameter at the given index.
	 *
	 * @param idx The index of the parameter.
	 * @return param The InstructionParameter at the given index.
	 */
140
	virtual InstructionParameter getParameter(const int idx) const {
141
142
143
144
145
146
147
148
149
		return parameter;
	}

	/**
	 * Return all of this Instruction's parameters.
	 *
	 * @return params This instructions parameters.
	 */
	virtual std::vector<InstructionParameter> getParameters() {
150
		return std::vector<InstructionParameter> { parameter };
151
152
153
154
155
156
157
158
159
	}

	/**
	 * Set this Instruction's parameter at the given index.
	 *
	 * @param idx The index of the parameter
	 * @param inst The instruction.
	 */
	virtual void setParameter(const int idx, InstructionParameter& inst) {
160
		parameter = inst;
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	}

	/**
	 * Return the number of InstructionParameters this Instruction contains.
	 *
	 * @return nInsts The number of instructions.
	 */
	virtual const int nParameters() {
		return 1;
	}

	/**
	 * Return true if this Instruction is parameterized.
	 *
	 * @return parameterized True if this Instruction has parameters.
	 */
	virtual bool isParameterized() {
		return true;
	}
	/**
	 * Returns true if this Instruction is composite,
	 * ie, contains other Instructions.
	 *
	 * @return isComposite True if this is a composite Instruction
	 */
186
187
188
	virtual bool isComposite() {
		return false;
	}
189
190
191
192
193
194

	/**
	 * Returns true if this Instruction is enabled
	 *
	 * @return enabled True if this Instruction is enabled.
	 */
195
196
197
	virtual bool isEnabled() {
		return enabled;
	}
198
199
200
201
202

	/**
	 * Disable this Instruction
	 */

203
204
205
	virtual void disable() {
		enabled = false;
	}
206
207
208
209

	/**
	 * Enable this Instruction.
	 */
210
211
212
	virtual void enable() {
		enabled = true;
	}
213
214
215
216
217
218
219
220

	EMPTY_DEFINE_VISITABLE()
};
}

}

#endif