This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
2-backend.js
230 lines (194 loc) · 6.59 KB
/
2-backend.js
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
* @license
*
* Copyright (c) 2017, IBM.
*
* This source code is licensed under the Apache License, Version 2.0 found in
* the LICENSE.txt file in the root directory of this source tree.
*/
'use strict';
const assert = require('assert');
const utilsTest = require('../../../../utils-test');
const expErrRegex = require('../errorRe');
const Cloud = require('../..');
const cloudNoToken = new Cloud();
// To avoid no token related errors.
const cloudFaked = new Cloud();
cloudFaked.token = 'a';
cloudFaked.userId = 'a';
describe('cloud:calibration', () => {
it('should fail if bad format in the "name" parameter', async () =>
utilsTest.throwsAsync(
() => cloudNoToken.calibration(1),
expErrRegex.formatStr,
));
it(
'should return the calibration info for the' +
'default backend if no parameter',
async () => {
const res = await cloudNoToken.calibration();
assert.deepEqual(Object.keys(res), [
'lastUpdateDate',
'qubits',
'multiQubitGates',
]);
assert.equal(typeof res.lastUpdateDate, 'string');
assert.equal(typeof res.qubits, 'object');
assert.equal(typeof res.multiQubitGates, 'object');
},
);
// We use a non existent one because we can´t know in advance the returned values here.
// TODO: The API should return an error in this case.
it('should return the calibration info for the selected backend', async () =>
assert.deepEqual(
Object.keys(await cloudNoToken.calibration('nonexistent')),
[],
));
});
describe('cloud:parameters', () => {
it('should fail if bad format in the "name" parameter', async () =>
utilsTest.throwsAsync(
() => cloudNoToken.parameters(1),
expErrRegex.formatStr,
));
it(
'should return the parameters info for the' +
'default backend if no parameter',
async () => {
const res = await cloudNoToken.parameters();
assert.deepEqual(Object.keys(res), [
'lastUpdateDate',
'fridgeParameters',
'qubits',
]);
assert.equal(typeof res.lastUpdateDate, 'string');
assert.equal(typeof res.fridgeParameters, 'object');
assert.equal(typeof res.qubits, 'object');
},
);
// We use a non existent one because we can´t know in advance the returned values here.
// TODO: The API should return an error in this case.
it('should return the parameters info for the selected backend', async () =>
assert.deepEqual(
Object.keys(await cloudNoToken.parameters('nonexistent')),
[],
));
});
describe('cloud:queues', () => {
it('should fail if bad format in the "name" parameter', async () =>
utilsTest.throwsAsync(() => cloudNoToken.queues(1), expErrRegex.formatStr));
it('should return the status of the queue of the default backend if no parameter', async () => {
const res = await cloudNoToken.queues();
assert.deepEqual(Object.keys(res), [
'state',
'status',
'lengthQueue',
'backend_version',
]);
assert.equal(typeof res.state, 'boolean');
assert.equal(typeof res.status, 'string');
assert.equal(typeof res.lengthQueue, 'number');
});
// We use a non existent one because we can´t know in advance the returned values here.
// TODO: The API should return an error in this case.
it('should return the queue info for the selected backend', async () =>
assert.deepEqual(await cloudNoToken.queues('nonexistent'), {}));
});
const expectedKeys = [
'name',
'version',
'status',
'serialNumber',
'description',
'attributes',
'gateSet',
'basisGates',
'onlineDate',
'chipName',
'deleted',
'specificConfiguration',
'id',
'topologyId',
'qconsole',
'url',
'internalId',
'simulator',
'allowQObject',
'nQubits',
'couplingMap',
];
describe('cloud:backend', () => {
it('should fail if no logged', async () =>
utilsTest.throwsAsync(
() => cloudNoToken.backend(),
expErrRegex.loginBefore,
));
it('should fail if bad format in the "name" parameter', async () =>
utilsTest.throwsAsync(() => cloudFaked.backend(1), expErrRegex.formatStr));
it('should return a backend with the default "name" parameter', async function t() {
if (!global.qiskit || !global.qiskit.cloud) {
this.skip();
}
const res = await global.qiskit.cloud.backend();
assert.deepEqual(Object.keys(res), expectedKeys);
assert.equal(res.name, 'ibmqx4');
});
it('should return a backend info for a valid "name" parameter', async function t() {
if (!global.qiskit || !global.qiskit.cloud) {
this.skip();
}
const name = 'ibmqx5';
const res = await global.qiskit.cloud.backend(name);
// TODO: Cloning to fix API inconsistency.
const expectedFix = expectedKeys.slice(0);
expectedFix.splice(5, 1);
expectedFix.splice(10, 1);
assert.deepEqual(Object.keys(res), expectedFix);
assert.equal(res.name, name);
});
// We use a non existent one because we can´t know in advance the returned values here.
// TODO: The API should return an error in this case.
it('should return the queue info for the selected backend', async function t() {
if (!global.qiskit || !global.qiskit.cloud) {
this.skip();
}
assert.deepEqual(await global.qiskit.cloud.backend('nonexistent'), {});
});
});
describe('cloud:backends', () => {
it('should fail if no logged', async () =>
utilsTest.throwsAsync(
() => cloudNoToken.backends(),
expErrRegex.loginBefore,
));
it('should return the online backends info', async function t() {
if (!global.qiskit || !global.qiskit.cloud) {
this.skip();
}
const res = await global.qiskit.cloud.backends();
assert.equal(res.length, 5);
assert.deepEqual(Object.keys(res[0]), expectedKeys);
});
it('should fail if bad format in the "onlySims" parameter', async () =>
utilsTest.throwsAsync(
() => cloudFaked.backends(1),
expErrRegex.formatBool,
));
it('should allow to ask only for simulators info', async function t() {
if (!global.qiskit || !global.qiskit.cloud) {
this.skip();
}
const res = await global.qiskit.cloud.backends(true);
assert.equal(res.length, 1);
assert.equal(Object.keys(res[0]).length, 13);
assert.equal(res[0].name, 'ibmq_qasm_simulator');
assert.equal(res[0].status, 'on');
assert.equal(res[0].description, 'online qasm simulator');
assert.equal(res[0].basisGates, 'u1,u2,u3,cx,id');
assert.equal(res[0].simulator, true);
assert(typeof res[0].onlineDate === 'string');
assert.equal(res[0].allowQObject, true);
assert.equal(res[0].nQubits, 32);
assert.equal(res[0].couplingMap, 'all-to-all');
});
});