-
Notifications
You must be signed in to change notification settings - Fork 2
/
g2q1.scm
196 lines (166 loc) · 4.57 KB
/
g2q1.scm
1
2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
186
187
188
189
190
191
192
193
194
;; =============================================================================
;;
;; g2q1.scm
;;
;; Additional configuration and machine-specific functions.
;;
;; =============================================================================
;;
;; Copyright (C) 2018 - 2022 Pablo Edronkin (pablo.edronkin at yahoo.com)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
;; License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;
;; =============================================================================
;;;; General notes:
;;
;; - Read sources for limitations on function parameters.
;; - Read at least the general notes of all scm files in this library before
;; use. Consider these files as your main documentation for g2q.
;; - Config for IBM Quantum Experience and Qiskit. This still needs development
;; in but might be needed to test QASM programs on IBM Q processors.
;;
;; Sources:
;;
;; - [1] Qiskit.org. (2019). Installing Qiskit — Qiskit 0.12.0 documentation.
;; [online] Available at: https://qiskit.org/documentation/install.html
;; [Accessed 7 Oct. 2019].
(define-module (g2q g2q1)
#:use-module (grsp grsp0)
#:export (g2q-version
g2q-ibm-config
g2q-qre-config
g2q-select-qpu
g2q-txt))
;; g2q-version - Returns the current version of the compiler.
;;
;; Keywords:
;;
;; - configuration, version
;;
(define (g2q-version)
(let ((res1 "g2q - v1.2.9"))
res1))
;; g2q-ibm-config - TODO: configuration for using IBM Q series machines;
;; equivalent to functions found on Qiskit IDE. (Deprecated).
;;
;; Keywords:
;;
;; - configuration, functions
;;
;; List elements:
;;
;; - 0: base uri for online access.
;; - 1: token.
;; - 2: subdir to post https execution requests.
;;
(define (g2q-ibm-config)
(let ((res1 (list "https://quantumexperience.ng.bluemix.net/api"
"your-token-goes-here"
"/codes/execute")))
res1))
;; g2q-qre-config - Configuration for using qre.
;;
;; Keywords:
;;
;; - configuration, qre
;;
;; Elements:
;;
;; - 0: json subdir.
;; - 1: sqlite3 subdir.
;; - 2: primary local (default) qpu.
;; - 3: secondary local qpu.
;; - 4: primary remote qpu.
;; - 5: secondary remote qpu.
;;
(define (g2q-qre-config)
(let ((res1 (list "data/json/"
"data/sqlite3/"
"qlib_simulator"
"ibmqx_simulator"
"qx_simulator"
"ibmqx_real")))
res1))
;; g2q-select-qpu - Menu for selecting the qpu that is to be used.
;;
;; Keywords:
;;
;; - configuration, qpu
;;
;; Output:
;;
;; - String containing the name of the selected qpu. Defaults to qlib_simulator.
;;
(define (g2q-select-qpu)
(let ((res1 3)
(res2 ""))
(newline)
(grsp-dl "Select qpu:")
(grsp-dl "0 - None (exit).")
(grsp-dl "1 - qlib_simulator.")
(grsp-dl "2 - qx_simulator.")
(grsp-dl "3 - ibmqx_simulator.")
(grsp-dl "4 - ibmqx_real.")
(set! res1 (read))
;; Not elegant, but works for now (needs to be reworked).
(if (< res1 0)
(set! res1 0))
(if (> res1 4)
(set! res1 0))
(if (= res1 0)
(set! res2 "none"))
(if (= res1 1)
(set! res2 (car(cdr(cdr(g2q-qre-config))))))
(if (= res1 2)
(set! res2 (car(cdr(cdr(cdr(cdr(g2q-qre-config))))))))
(if (= res1 4)
(set! res2 (car(cdr(cdr(cdr(cdr(cdr(g2q-qre-config)))))))))
(if (= res1 3)
(set! res2 (car(cdr(cdr(cdr(g2q-qre-config)))))))
res2))
;; g2q-txt - Defines some string constants that are intrinsic to g2q.
;;
;; Keywords:
;;
;; - configuration, constants
;;
;; Parameters:
;;
;; - p_n1: string number.
;;
(define (g2q-txt p_n1)
(let ((res1 ""))
(cond ((= p_n1 0)
(set! res1 "];"))
((= p_n1 1)
(set! res1 "\n"))
((= p_n1 2)
(set! res1 ";\n"))
((= p_n1 3)
(set! res1 "];\n"))
((= p_n1 4)
(set! res1 ") "))
((= p_n1 5)
(set! res1 "if("))
((= p_n1 6)
(set! res1 "// "))
((= p_n1 7)
(set! res1 "charset=utf-8"))
((= p_n1 8)
(set! res1 "application/x-www-form-urlencoded;"))
((= p_n1 9)
(set! res1 "na"))
((= p_n1 10)
(set! res1 ", ")))
res1))