@@ -2937,12 +2937,12 @@ QuantumCircuit.prototype.matrixHasComplexElement = function(M) {
29372937 for ( var c = 0 ; c < row . length ; c ++ ) {
29382938 var cell = row [ c ] ;
29392939
2940- if ( cell instanceof math . Complex ) {
2940+ if ( cell instanceof math . Complex || ( ( typeof cell == "object" ) && ( ( cell . mathjs && cell . mathjs == "Complex" ) || ( cell . type && cell . type == "Complex" ) ) ) ) {
29412941 return true ;
29422942 }
29432943 }
29442944 } else {
2945- if ( row instanceof math . Complex ) {
2945+ if ( row instanceof math . Complex || ( ( typeof row == "object" ) && ( ( row . mathjs && row . mathjs == "Complex" ) || ( row . type && row . type == "Complex" ) ) ) ) {
29462946 return true ;
29472947 }
29482948 }
@@ -3420,6 +3420,7 @@ QuantumCircuit.prototype.isEmptyPlace = function(col, wires, usingCregs) {
34203420 for ( var wire = minWire ; wire <= maxWire ; wire ++ ) {
34213421 if ( ! this . isEmptyCell ( col , wire ) ) {
34223422 allEmpty = false ;
3423+ break ;
34233424 }
34243425 }
34253426
@@ -3444,6 +3445,7 @@ QuantumCircuit.prototype.lastNonEmptyPlace = function(wires, usingCregs) {
34443445 for ( var wire = minWire ; wire <= maxWire ; wire ++ ) {
34453446 if ( ! this . isEmptyCell ( col , wire ) ) {
34463447 allEmpty = false ;
3448+ break ;
34473449 }
34483450 }
34493451 }
@@ -4121,15 +4123,20 @@ QuantumCircuit.prototype.chanceMap = function() {
41214123} ;
41224124
41234125
4124- function binStr ( i , len ) {
4125- var bin = i . toString ( 2 ) ;
4126+ function binStr ( n , len ) {
4127+ var bin = n . toString ( 2 ) ;
41264128 while ( bin . length < len ) {
41274129 bin = "0" + bin ;
41284130 }
41294131 return bin ;
41304132}
41314133
41324134
4135+ function reverseBitwise ( n , len ) {
4136+ return parseInt ( binStr ( n , len ) . split ( "" ) . reverse ( ) . join ( "" ) , 2 ) ;
4137+ }
4138+
4139+
41334140QuantumCircuit . prototype . resetQubit = function ( wire , value ) {
41344141 var U = [
41354142 [ 0 , 0 ] ,
@@ -7455,6 +7462,7 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
74557462 var centerX = gateX + ( options . cellWidth / 2 ) ;
74567463
74577464 var paramsStr = "" ;
7465+ var paramsCount = 0 ;
74587466 for ( var paramName in gate . options . params ) {
74597467 if ( paramsStr ) {
74607468 paramsStr += ", " ;
@@ -7470,6 +7478,11 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
74707478 }
74717479
74727480 paramsStr += paramVal ;
7481+ paramsCount ++ ;
7482+ }
7483+
7484+ if ( paramsStr . length > 26 ) {
7485+ paramsStr = "(" + paramsCount + " params)" ;
74737486 }
74747487 svg += "<text class=\"qc-gate-params\" x=\"" + centerX + "\" y=\"" + ( gateY + options . cellHeight + options . paramTextHeight ) + "\" dominant-baseline=\"hanging\" text-anchor=\"middle\" font-size=\"75%\">" + paramsStr + "</text>" ;
74757488 }
@@ -7696,7 +7709,7 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
76967709 if ( options . customGate ) {
76977710 initSymbol = qubitLetter ( wire , numRows ) ;
76987711 }
7699- svg += "<text class=\"qc-wire-init\" x=\"0\" y=\"" + wireY + "\" dominant-baseline=\"middle\" text-anchor=\"start\">|" + initSymbol + "⟩ </text>" ;
7712+ svg += "<text class=\"qc-wire-init\" x=\"0\" y=\"" + wireY + "\" dominant-baseline=\"middle\" text-anchor=\"start\">|" + initSymbol + "⟩ </text>" ;
77007713 svg += "<line class=\"qc-wire\" x1=\"" + options . wireMargin + "\" x2=\"" + totalWireWidth + "\" y1=\"" + wireY + "\" y2=\"" + wireY + "\" stroke=\"" + options . wireColor + "\" stroke-width=\"" + options . wireWidth + "\" />" ;
77017714 svg += "<text class=\"qc-wire-label\" x=\"" + options . wireMargin + "\" y=\"" + ( wireY - ( options . wireTextHeight * 2 ) ) + "\" dominant-baseline=\"hanging\" text-anchor=\"start\" font-size=\"75%\">q" + wire + "</text>" ;
77027715 }
@@ -12436,7 +12449,7 @@ QuantumCircuit.prototype.continue = function() {
1243612449 } ) ;
1243712450} ;
1243812451
12439- QuantumCircuit . prototype . stateAsArray = function ( onlyPossible , skipItems , blockSize ) {
12452+ QuantumCircuit . prototype . stateAsArray = function ( onlyPossible , skipItems , blockSize , reverseBits ) {
1244012453 var state = [ ] ;
1244112454
1244212455 var numAmplitudes = this . numAmplitudes ( ) ;
@@ -12446,7 +12459,13 @@ QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockS
1244612459
1244712460 var count = 0 ;
1244812461 for ( var i = 0 ; i < numAmplitudes ; i ++ ) {
12449- var amplitude = math . round ( this . state [ i ] || math . complex ( 0 , 0 ) , 14 ) ;
12462+ var ampIndex = i ;
12463+ if ( reverseBits ) {
12464+ ampIndex = reverseBitwise ( i , this . numQubits ) ;
12465+ }
12466+
12467+ var amplitude = math . round ( this . state [ ampIndex ] || math . complex ( 0 , 0 ) , 14 ) ;
12468+
1245012469 if ( ! onlyPossible || ( amplitude . re || amplitude . im ) ) {
1245112470 if ( count >= skipItems ) {
1245212471 var indexBinStr = i . toString ( 2 ) ;
@@ -12485,7 +12504,7 @@ QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockS
1248512504 return state ;
1248612505} ;
1248712506
12488- QuantumCircuit . prototype . stateAsSimpleArray = function ( ) {
12507+ QuantumCircuit . prototype . stateAsSimpleArray = function ( reverseBits ) {
1248912508
1249012509 var numAmplitudes = this . numAmplitudes ( ) ;
1249112510 if ( ! this . state ) {
@@ -12494,7 +12513,12 @@ QuantumCircuit.prototype.stateAsSimpleArray = function() {
1249412513
1249512514 var state = [ ] ;
1249612515 for ( var i = 0 ; i < numAmplitudes ; i ++ ) {
12497- state . push ( math . round ( this . state [ i ] || math . complex ( 0 , 0 ) , 14 ) ) ;
12516+ var ampIndex = i ;
12517+ if ( reverseBits ) {
12518+ ampIndex = reverseBitwise ( i , this . numQubits ) ;
12519+ }
12520+
12521+ state . push ( math . round ( this . state [ ampIndex ] || math . complex ( 0 , 0 ) , 14 ) ) ;
1249812522 }
1249912523 return state ;
1250012524} ;
0 commit comments