Skip to content

Commit 3d0d130

Browse files
committed
Merge branch 'develop'
2 parents 748a857 + df0ba92 commit 3d0d130

File tree

2 files changed

+572
-21
lines changed

2 files changed

+572
-21
lines changed

lib/quantum-circuit.js

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5994,18 +5994,18 @@ QuantumCircuit.prototype.exportQuirk = function(decompose) {
59945994
isDecomposeCustomCircuit = true;
59955995
}
59965996
}
5997-
5998-
if(isDecomposeCustomCircuit){
5999-
circuit.gates.map(function(circuitGate, index){
6000-
circuitGate.map(function(gateToRemove){
6001-
if(gateToRemove && gateToRemove.name == gate.name){
6002-
circuit.removeGate(gateToRemove.id);
6003-
}
6004-
});
6005-
});
6006-
}else {
6007-
gatesToBeAdded = [];
6008-
}
5997+
}
5998+
5999+
if(isDecomposeCustomCircuit){
6000+
circuit.gates.map(function(circuitGate, index){
6001+
circuitGate.map(function(gateToRemove){
6002+
if(gateToRemove && gateToRemove.name == gate.name){
6003+
circuit.removeGate(gateToRemove.id);
6004+
}
6005+
});
6006+
});
6007+
}else {
6008+
gatesToBeAdded = [];
60096009
}
60106010
}
60116011
}
@@ -6019,6 +6019,26 @@ QuantumCircuit.prototype.exportQuirk = function(decompose) {
60196019
}
60206020
});
60216021

6022+
var previousColumn = null;
6023+
var previousGate = null;
6024+
for(var column = 0; column < numCols; column++) {
6025+
for(var wire = 0; wire < circuit.numQubits; wire++) {
6026+
var gate = circuit.getGateAt(column, wire);
6027+
if(gate){
6028+
// if(previousGate){
6029+
// console.log(previousGate.name, gate.name, previousGate.connector, previousColumn, column)
6030+
// }
6031+
if(previousGate && previousGate.name != gate.name && previousGate.connector != 0 && previousColumn == column){
6032+
circuit.removeGate(gate.id);
6033+
circuit.insertGate(gate.name, gate.column + 1, gate.wires, gate.options);
6034+
// console.log(gate.name, previousColumn, column)
6035+
}
6036+
previousGate = gate;
6037+
previousColumn = column;
6038+
}
6039+
}
6040+
}
6041+
60226042
var numCols = circuit.numCols();
60236043
for(var column = 0; column < numCols; column++) {
60246044
var quirkColumn = [];
@@ -9291,19 +9311,27 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
92919311
var hybrid = !!isExportPyAQASM ? options.hybrid : false;
92929312

92939313
var circuit = null;
9314+
var tempCircuit = null;
92949315

92959316
shots = shots || 1024;
92969317

92979318
if(typeof hybrid == "undefined") {
92989319
hybrid = this.options ? !!this.options.hybrid : false;
92999320
}
93009321

9322+
var obj = null;
93019323
// decompose
93029324
if(decompose) {
93039325
circuit = new QuantumCircuit();
9304-
circuit.load(this.save(true));
9326+
tempCircuit = new QuantumCircuit();
9327+
obj = this.save(true);
9328+
circuit.load(obj);
9329+
tempCircuit.load(obj);
93059330
} else {
93069331
circuit = this;
9332+
obj = this.save(false);
9333+
tempCircuit = new QuantumCircuit();
9334+
tempCircuit.load(obj);
93079335
}
93089336

93099337
var mathToStringHandler = function(node, options) {
@@ -9357,6 +9385,44 @@ QuantumCircuit.prototype.exportToAQASM = function(options, isExportPyAQASM, expo
93579385

93589386
indentDepth = indentDepth || 0;
93599387

9388+
var gatesToBeAdded = [];
9389+
if(!isExportPyAQASM){
9390+
if(!decompose) {
9391+
var numCols = tempCircuit.numCols();
9392+
for(var column = numCols - 1; column >= 0; column--) {
9393+
for(var wire = 0; wire < tempCircuit.numQubits; wire++) {
9394+
var gate = tempCircuit.gates[wire][column];
9395+
if(gate && gate.connector == 0 && !tempCircuit.basicGates[gate.name]) {
9396+
customDecomposedCircuit = tempCircuit.decomposeGateAt(column, wire);
9397+
var isDecomposeCustomCircuit = false;
9398+
for(var decomposedColumn = 0; decomposedColumn < customDecomposedCircuit.numCols(); decomposedColumn++) {
9399+
for(var decomposedWire = 0; decomposedWire < customDecomposedCircuit.numQubits; decomposedWire++) {
9400+
var gateInCustomCircuit = customDecomposedCircuit.getGateAt(decomposedColumn, decomposedWire);
9401+
9402+
if(gateInCustomCircuit && gateInCustomCircuit.connector == 0){
9403+
gatesToBeAdded.push(gateInCustomCircuit);
9404+
}
9405+
9406+
circuit.gates.map(function(circuitGate, index){
9407+
circuitGate.map(function(gateToRemove){
9408+
if(gateToRemove && gateToRemove.name == gate.name){
9409+
circuit.removeGate(gateToRemove.id);
9410+
}
9411+
});
9412+
});
9413+
}
9414+
}
9415+
}
9416+
}
9417+
}
9418+
}
9419+
gatesToBeAdded.map(function(gateToAdd){
9420+
if(gateToAdd){
9421+
circuit.insertGate(gateToAdd.name, gateToAdd.column, gateToAdd.wires, gateToAdd.options);
9422+
}
9423+
});
9424+
}
9425+
93609426
var aqasm = "";
93619427
var indent = getIndent(indentDepth);
93629428
var usedGates = circuit.usedGates();

0 commit comments

Comments
 (0)