DWQMICompiler.hpp 4.52 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
33
34
35
36
#ifndef QUANTUM_AQC_COMPILERS_DWQMICOMPILER_HPP_
#define QUANTUM_AQC_COMPILERS_DWQMICOMPILER_HPP_

#include "Compiler.hpp"
#include "Utils.hpp"
#include "DWIR.hpp"
37
38
#include "DWGraph.hpp"
#include "EmbeddingAlgorithm.hpp"
39
40
41
42
43

namespace xacc {

namespace quantum {

44
/**
45
46
47
48
49
50
51
52
 * The DWQMICompiler is an XACC Compiler that compiles
 * D-Wave quantum machine instructions to produce an
 * appropriate Ising form for execution on the D-Wave QPU.
 *
 * This compilation leverages XACC EmbeddingAlgorithms to
 * compute the minor graph embedding represented by the
 * input source kernel code to output the embedded Ising
 * graph for D-Wave execution.
53
54
 */
class DWQMICompiler: public xacc::Compiler {
55

56
public:
57

58
59
60
61
	/**
	 * The Compiler.
	 */
	DWQMICompiler() {}
62

63
	/**
64
65
66
67
68
69
	 * Compile the given kernel code for the
	 * given D-Wave Accelerator.
	 *
	 * @param src The QMI source code
	 * @param acc Reference to the D-Wave Accelerator
	 * @return
70
71
72
	 */
	virtual std::shared_ptr<xacc::IR> compile(const std::string& src,
			std::shared_ptr<Accelerator> acc);
73

74
	/**
75
76
	 * This method is not implemented - we must always have
	 * D-Wave Accelerator connectivity information for compilation.
77
78
79
80
	 *
	 * @return
	 */
	virtual std::shared_ptr<xacc::IR> compile(const std::string& src);
81

82
83
84
85
86
87
88
	/**
	 * Return the name of this Compiler
	 * @return name Compiler name
	 */
	virtual const std::string getName() {
		return "dwave-qmi";
	}
89

90
91
92
93
94
	/**
	 * Return the command line options for this compiler
	 *
	 * @return options Description of command line options.
	 */
95
96
97
98
	virtual std::shared_ptr<options_description> getOptions() {
		auto desc = std::make_shared<options_description>(
				"D-Wave QMI Compiler Options");
		desc->add_options()("dwave-embedding", value<std::string>(),
99
100
101
				"Provide the name of the Embedding Algorithm to use during compilation.")(
				"dwave-parameter-setter", value<std::string>(),
				"Provide the name of the "
102
103
104
						"ParameterSetter to map logical parameters to physical parameters.")
						("dwave-load-embedding", value<std::string>(), "Use the embedding in the given file.")
						("dwave-persist-embedding", value<std::string>(), "Persist the computed embedding to the given file name.");
105
106
107
		return desc;
	}

108
109
110
111
	/**
	 * Register this Compiler with the framework.
	 */
	static void registerCompiler() {
112
113
114
		DWQMICompiler c;
		xacc::RegisterCompiler<xacc::quantum::DWQMICompiler> DWQMITEMP(
				"dwave-qmi", c.getOptions());
115
116
	}

117
118
119
120
121
122
	/**
	 * We don't allow translations for the DW Compiler.
	 * @param bufferVariable
	 * @param function
	 * @return
	 */
123
124
125
126
	virtual const std::string translate(const std::string& bufferVariable,
			std::shared_ptr<Function> function) {
		XACCError("DWQMICompiler::translate - Method not implemented");
	};
127

128
129
130
131
	/**
	 * The destructor
	 */
	virtual ~DWQMICompiler() {}
132

133
};
134

135
RegisterCompiler(xacc::quantum::DWQMICompiler)
136
137
138
139
140

}

}

141
#endif