Skip to content

Commit 8932d7b

Browse files
committed
Merge branch 'aqasm-fix' into develop
2 parents 75864b2 + 0498c1f commit 8932d7b

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

lib/quantum-circuit.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9291,19 +9291,27 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
92919291
var hybrid = !!isExportPyAQASM ? options.hybrid : false;
92929292

92939293
var circuit = null;
9294+
var tempCircuit = null;
92949295

92959296
shots = shots || 1024;
92969297

92979298
if(typeof hybrid == "undefined") {
92989299
hybrid = this.options ? !!this.options.hybrid : false;
92999300
}
93009301

9302+
var obj = null;
93019303
// decompose
93029304
if(decompose) {
93039305
circuit = new QuantumCircuit();
9304-
circuit.load(this.save(true));
9306+
tempCircuit = new QuantumCircuit();
9307+
obj = this.save(true);
9308+
circuit.load(obj);
9309+
tempCircuit.load(obj);
93059310
} else {
93069311
circuit = this;
9312+
obj = this.save(false);
9313+
tempCircuit = new QuantumCircuit();
9314+
tempCircuit.load(obj);
93079315
}
93089316

93099317
var mathToStringHandler = function(node, options) {
@@ -9357,6 +9365,44 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
93579365

93589366
indentDepth = indentDepth || 0;
93599367

9368+
var gatesToBeAdded = [];
9369+
if(!isExportPyAQASM){
9370+
if(!decompose) {
9371+
var numCols = tempCircuit.numCols();
9372+
for(var column = numCols - 1; column >= 0; column--) {
9373+
for(var wire = 0; wire < tempCircuit.numQubits; wire++) {
9374+
var gate = tempCircuit.gates[wire][column];
9375+
if(gate && gate.connector == 0 && !tempCircuit.basicGates[gate.name]) {
9376+
customDecomposedCircuit = tempCircuit.decomposeGateAt(column, wire);
9377+
var isDecomposeCustomCircuit = false;
9378+
for(var decomposedColumn = 0; decomposedColumn < customDecomposedCircuit.numCols(); decomposedColumn++) {
9379+
for(var decomposedWire = 0; decomposedWire < customDecomposedCircuit.numQubits; decomposedWire++) {
9380+
var gateInCustomCircuit = customDecomposedCircuit.getGateAt(decomposedColumn, decomposedWire);
9381+
9382+
if(gateInCustomCircuit && gateInCustomCircuit.connector == 0){
9383+
gatesToBeAdded.push(gateInCustomCircuit);
9384+
}
9385+
9386+
circuit.gates.map(function(circuitGate, index){
9387+
circuitGate.map(function(gateToRemove){
9388+
if(gateToRemove && gateToRemove.name == gate.name){
9389+
circuit.removeGate(gateToRemove.id);
9390+
}
9391+
});
9392+
});
9393+
}
9394+
}
9395+
}
9396+
}
9397+
}
9398+
}
9399+
gatesToBeAdded.map(function(gateToAdd){
9400+
if(gateToAdd){
9401+
circuit.insertGate(gateToAdd.name, gateToAdd.column, gateToAdd.wires, gateToAdd.options);
9402+
}
9403+
});
9404+
}
9405+
93609406
var aqasm = "";
93619407
var indent = getIndent(indentDepth);
93629408
var usedGates = circuit.usedGates();

0 commit comments

Comments
 (0)