Skip to content

Commit 98e900d

Browse files
Khesim/ibm system update (#86)
* Added qasm simulator as default quantum backend. * Corrected error message for large circuits. * Updating ibm system node defaults. * Fixed default settings for running on IBM Quantum * Fixed qasm simulator overriding preferred system. * Refactor redundant code. * Restructure if/else statement. * Shot min & default value set to 1 * Typo resulting in IBM Quantum QASM bug * redundant error handling * Removed tag icon in front of node property input fields * New node properties HTML interface Co-authored-by: Theo Reignier <[email protected]>
1 parent 1f8fe01 commit 98e900d

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

quantum/nodes/ibm-quantum-system/ibm-quantum-system.html

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
defaults: {
66
name: { value: "" },
77
api_token: { value: "", required: true },
8+
chosen_system: { value: "" },
89
preferred_backend: { value: "" },
10+
shots: {
11+
value: 1,
12+
validate: function (x) {
13+
x = parseInt(x);
14+
if (Number.isInteger(x) && x > 0) {
15+
return true;
16+
} else {
17+
return false;
18+
}
19+
},
20+
},
921
preferred_output: { value: "" },
1022
},
1123
inputs: 1,
@@ -15,7 +27,7 @@
1527
label: function () {
1628
return this.name || "ibm quantum system";
1729
},
18-
});
30+
})
1931
</script>
2032

2133
<script type="text/html" data-template-name="ibm-quantum-system">
@@ -32,23 +44,35 @@
3244
<input type="text" id="node-input-api_token" placeholder="API Token" style="margin-bottom: 20px;"/>
3345
</div>
3446

35-
<div class="form-row">
36-
<label for="node-input-preferred_backend" id="user-backend"
37-
>Quantum Backend
38-
</label>
47+
<div style="width:40%; text-align:center; float:left; margin-bottom: 40px;">
48+
<label for="node-input-chosen_system">Least Busy Backend</label>
49+
<select name="chosen_system" id="node-input-chosen_system" style="width:85%">
50+
<option value="Simulator">Simulator</option>
51+
<option value="Qubit_System">Quantum System</option>
52+
</select>
53+
</div>
54+
<div style="width:5%; font-size:10pt; text-align:center; float:left; margin-top: 20px;">OR</div>
55+
<div style="width:40%; text-align:center; float:left; margin-bottom: 40px;">
56+
<label for="node-input-preferred_backend" id="user-backend">Specific Backend</label>
3957
<input
4058
type="text"
4159
id="node-input-preferred_backend"
4260
placeholder="Preferred Backend"
43-
style="margin-bottom: 20px;"
61+
style="width:85%"
4462
/>
4563
</div>
4664

65+
<div class="form-row">
66+
<label for="node-input-shots">Shots</label>
67+
<input type="number" min="1" id="node-input-shots" placeholder="1000"/>
68+
</div>
69+
4770
<div class="form-row">
4871
<label for="node-input-preferred_output">Output Format</label>
4972
<select name="preferred_output" id="node-input-preferred_output">
50-
<option value="Verbose">Verbose</option>
5173
<option value="Results">Results Only</option>
74+
<option value="Verbose">Verbose</option>
5275
</select>
5376
</div>
54-
</script>
77+
78+
</script>

quantum/nodes/ibm-quantum-system/ibm-quantum-system.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ module.exports = function(RED) {
99
function IBMQuantumSystemNode(config) {
1010
RED.nodes.createNode(this, config);
1111
this.apiToken = config.api_token;
12+
this.chosenSystem = config.chosen_system;
1213
this.preferredBackend = config.preferred_backend;
1314
this.outputPreference = config.preferred_output;
15+
this.shots = config.shots || 1;
1416
this.qubits = [];
1517
this.qreg = '';
1618
const node = this;
@@ -34,6 +36,7 @@ module.exports = function(RED) {
3436
return;
3537
}
3638

39+
3740
// If the quantum circuit does not have registers
3841
if (typeof(msg.payload.register) === 'undefined') {
3942
node.qreg = undefined;
@@ -108,13 +111,21 @@ module.exports = function(RED) {
108111
if (node.preferredBackend) {
109112
script += util.format(snippets.IBMQ_SYSTEM_PREFERRED, node.apiToken, node.preferredBackend);
110113
} else {
111-
script += util.format(snippets.IBMQ_SYSTEM_DEFAULT, node.apiToken, node.qubits.length);
114+
if (node.chosenSystem == 'Qubit_System') {
115+
script += util.format(snippets.IBMQ_SYSTEM_DEFAULT, node.apiToken, node.qubits.length, 'False');
116+
} else {
117+
if (node.qubits.length > 32) {
118+
script += util.format(snippets.IBMQ_SYSTEM_DEFAULT, node.apiToken, node.qubits.length, 'True');
119+
} else {
120+
script += util.format(snippets.IBMQ_SYSTEM_QASM, node.apiToken);
121+
}
122+
}
112123
}
113124

114125
if (node.outputPreference == 'Verbose') {
115-
script += snippets.IBMQ_SYSTEM_VERBOSE;
126+
script += util.format(snippets.IBMQ_SYSTEM_VERBOSE, node.shots);
116127
} else {
117-
script += snippets.IBMQ_SYSTEM_RESULT;
128+
script += util.format(snippets.IBMQ_SYSTEM_RESULT, node.shots);
118129
}
119130

120131
await shell.execute(script, (err, data) => {

quantum/nodes/local-simulator/local-simulator.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<input type="text" id="node-input-name" placeholder="Name" />
2525
</div>
2626
<div class="form-row">
27-
<label for="node-input-shots"><i class="fa fa-tag"></i> Shots</label>
27+
<label for="node-input-shots">Shots</label>
2828
<input type="number" id="node-input-shots" placeholder="1000"/>
2929
</div>
3030
</script>

quantum/snippets.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ counts = result.get_counts()
5656
print(counts)
5757
`;
5858

59+
const IBMQ_SYSTEM_QASM =
60+
`from qiskit.providers.ibmq import least_busy
61+
provider = IBMQ.enable_account('%s')
62+
backend_service = provider.get_backend('ibmq_qasm_simulator')
63+
`;
64+
5965
const IBMQ_SYSTEM_DEFAULT =
6066
`from qiskit.providers.ibmq import least_busy
6167
provider = IBMQ.enable_account('%s')
62-
backends = provider.backends(filters=lambda x: x.configuration().n_qubits >= %s)
68+
backends = provider.backends(filters=lambda x: (x.configuration().n_qubits >= %s and x.configuration().simulator == %s))
6369
backend_service = least_busy(backends)
6470
`;
6571

@@ -69,12 +75,12 @@ backend_service = provider.get_backend('%s')
6975
`;
7076

7177
const IBMQ_SYSTEM_VERBOSE =
72-
`job = execute(qc, backend=backend_service)
78+
`job = execute(qc, backend=backend_service, shots=%s)
7379
job.result()
7480
`;
7581

7682
const IBMQ_SYSTEM_RESULT =
77-
`job = execute(qc, backend=backend_service)
83+
`job = execute(qc, backend=backend_service, shots=%s)
7884
counts = job.result().get_counts()
7985
print(counts)
8086
`;
@@ -167,6 +173,7 @@ module.exports = {
167173
MEASURE,
168174
LOCAL_SIMULATOR,
169175
MULTI_CONTROLLED_U_GATE,
176+
IBMQ_SYSTEM_QASM,
170177
IBMQ_SYSTEM_DEFAULT,
171178
IBMQ_SYSTEM_PREFERRED,
172179
IBMQ_SYSTEM_VERBOSE,

0 commit comments

Comments
 (0)