Skip to content

Commit 86e8033

Browse files
committed
added reset and measure
1 parent b8e1134 commit 86e8033

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

lib/quantum-circuit.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9051,6 +9051,10 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
90519051
if(!isExportPyAQASM){
90529052
aqasm += indent + "BEGIN\n";
90539053
aqasm += indent + "qubits " + numQubits + "\n";
9054+
9055+
if (circuit.cregs){
9056+
aqasm += indent + "cbits " + circuit.cregs.length + "\n";
9057+
}
90549058
}else {
90559059
if(exportAsGateName){
90569060
var args = "";
@@ -9121,7 +9125,11 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
91219125
}
91229126
}
91239127

9124-
unsupportedGateDefinition += "], matrix_generator=" + gateUnitary + ", arity=" + circuit.numQubits +")\n";
9128+
if(basicGate.matrix){
9129+
arity = math.log2(basicGate.matrix.length);
9130+
}
9131+
9132+
unsupportedGateDefinition += "], matrix_generator=" + gateUnitary + ", arity=" + arity +")\n";
91259133
}
91269134
}
91279135
} else {
@@ -9154,7 +9162,13 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
91549162
}
91559163

91569164
aqasm += indent + "program = Program()\n";
9157-
aqasm += indent + "qubits_reg = program.qalloc("+ circuit.numQubits +")\n\n";
9165+
aqasm += indent + "qubits_reg = program.qalloc("+ circuit.numQubits +")\n";
9166+
9167+
for(var cregName in circuit.cregs){
9168+
aqasm += indent + cregName + " = program.calloc(" + circuit.cregs[cregName].length + ")\n";
9169+
}
9170+
9171+
aqasm += "\n";
91589172

91599173
var globalParams = this.options && this.options.params ? this.options.params : {};
91609174
if(this.params.length) {
@@ -9205,14 +9219,31 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
92059219
var gate = circuit.getGateAt(column, wire);
92069220
if(gate && gate.connector == 0) {
92079221
var gateDef = circuit.getGateDef(gate.name);
9222+
var name = "";
92089223
if(gate.options && gate.options.params){
92099224
gateParams = gate.options.params;
92109225
}
9226+
9227+
if(gate.name == "measure"){
9228+
if(!isExportPyAQASM) {
9229+
name += "MEAS"
9230+
} else {
9231+
name += "program.measure";
9232+
}
9233+
}
9234+
9235+
if(gate.name == "reset"){
9236+
if(!isExportPyAQASM) {
9237+
name += "RESET"
9238+
} else {
9239+
name += "program.reset";
9240+
}
9241+
}
9242+
92119243
if(gateDef && gateDef.exportInfo){
92129244
if(gateDef.exportInfo.aqasm){
92139245
var aqasmInfo = gateDef.exportInfo.aqasm;
92149246
var aqasmInfoName = "";
9215-
var name = "";
92169247
if(aqasmInfo.name){
92179248
if(gateDef.params.length){
92189249
gateDef.params.map(function(param){
@@ -9299,14 +9330,14 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
92999330
name += ")";
93009331
}
93019332
}
9333+
}
93029334

9303-
aqasm += indent + name;
9335+
aqasm += indent + name;
93049336

9305-
if(!isExportPyAQASM){
9306-
aqasm += " ";
9307-
}else {
9308-
aqasm += "(";
9309-
}
9337+
if(!isExportPyAQASM){
9338+
aqasm += " ";
9339+
}else {
9340+
aqasm += "(";
93109341
}
93119342
}
93129343

@@ -9329,6 +9360,10 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
93299360
argCount = argCount + 1;
93309361
}
93319362

9363+
if(gate.options && gate.options.creg){
9364+
aqasm += ", " + gate.options.creg.name + "[" + gate.options.creg.bit + "]";
9365+
}
9366+
93329367
if(isExportPyAQASM){
93339368
aqasm += ")";
93349369
}
@@ -9355,6 +9390,7 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
93559390
aqasm += indent + "for state in job_result:\n";
93569391
aqasm += indent + " string_state = str(state.state)\n";
93579392
aqasm += indent + " string_state = string_state[string_state.find('|') + 1: string_state.find('>')]\n";
9393+
aqasm += indent + " string_state = string_state[::-1]\n"
93589394
aqasm += indent + " if counts.get(string_state) is None:\n";
93599395
aqasm += indent + " counts.update({string_state: 1})\n";
93609396
aqasm += indent + " else:\n";

0 commit comments

Comments
 (0)