@@ -20,7 +20,6 @@ var formatComplex2 = function(re, im, options) {
2020 var opt = JSON . parse ( JSON . stringify ( options ) ) ;
2121 opt . plusChar = "+" ;
2222 var sim = formatFloat ( im , opt ) ;
23-
2423 return sre + sim + ( options . iotaChar ? options . iotaChar : "i" ) ;
2524} ;
2625
@@ -5754,6 +5753,7 @@ QuantumCircuit.prototype.exportQuirk = function(decompose) {
57545753 var customGateCircuit = new QuantumCircuit ( ) ;
57555754
57565755
5756+
57575757 var gatesToBeAdded = [ ] ;
57585758
57595759 if ( ! decompose ) {
@@ -5764,24 +5764,31 @@ QuantumCircuit.prototype.exportQuirk = function(decompose) {
57645764 if ( gate && gate . connector == 0 && ! tempCircuit . basicGates [ gate . name ] ) {
57655765 customDecomposedCircuit = tempCircuit . decomposeGateAt ( column , wire ) ;
57665766 var isDecomposeCustomCircuit = false ;
5767- for ( var decomposedColumn = 0 ; decomposedColumn < numCols ; decomposedColumn ++ ) {
5767+ for ( var decomposedColumn = 0 ; decomposedColumn < customDecomposedCircuit . numCols ( ) ; decomposedColumn ++ ) {
57685768 for ( var decomposedWire = 0 ; decomposedWire < customDecomposedCircuit . numQubits ; decomposedWire ++ ) {
57695769 var gateInCustomCircuit = customDecomposedCircuit . getGateAt ( decomposedColumn , decomposedWire ) ;
5770- gatesToBeAdded . push ( gateInCustomCircuit ) ;
5770+
5771+ if ( gateInCustomCircuit && gateInCustomCircuit . connector == 0 ) {
5772+ gatesToBeAdded . push ( gateInCustomCircuit ) ;
5773+ }
5774+
57715775 if ( gateInCustomCircuit ) {
57725776 var basicGateInCustomCircuit = customDecomposedCircuit . basicGates [ gateInCustomCircuit . name ] ;
57735777 if ( basicGateInCustomCircuit . exportInfo && ! basicGateInCustomCircuit . exportInfo . quirk ) {
57745778 isDecomposeCustomCircuit = true ;
57755779 }
57765780 }
5777-
5781+
57785782 if ( isDecomposeCustomCircuit ) {
5779- var tempGates = circuit . gates ;
57805783 circuit . gates . map ( function ( circuitGate , index ) {
5781- if ( circuitGate [ 0 ] && circuitGate [ 0 ] . name == gate . name ) {
5782- circuit . removeGate ( circuitGate [ 0 ] . id ) ;
5783- }
5784+ circuitGate . map ( function ( gateToRemove ) {
5785+ if ( gateToRemove && gateToRemove . name == gate . name ) {
5786+ circuit . removeGate ( gateToRemove . id ) ;
5787+ }
5788+ } ) ;
57845789 } ) ;
5790+ } else {
5791+ gatesToBeAdded = [ ] ;
57855792 }
57865793 }
57875794 }
@@ -5792,7 +5799,7 @@ QuantumCircuit.prototype.exportQuirk = function(decompose) {
57925799
57935800 gatesToBeAdded . map ( function ( gateToAdd ) {
57945801 if ( gateToAdd ) {
5795- circuit . addGate ( gateToAdd . name , gateToAdd . column , gateToAdd . wires , gateToAdd . options ) ;
5802+ circuit . insertGate ( gateToAdd . name , gateToAdd . column , gateToAdd . wires , gateToAdd . options ) ;
57965803 }
57975804 } ) ;
57985805
0 commit comments