diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..44e0be8
Binary files /dev/null and b/.DS_Store differ
diff --git a/lib/.DS_Store b/lib/.DS_Store
new file mode 100644
index 0000000..8838284
Binary files /dev/null and b/lib/.DS_Store differ
diff --git a/lib/quantum-circuit.js b/lib/quantum-circuit.js
index fe737d9..640963b 100644
--- a/lib/quantum-circuit.js
+++ b/lib/quantum-circuit.js
@@ -2937,12 +2937,12 @@ QuantumCircuit.prototype.matrixHasComplexElement = function(M) {
for(var c = 0; c < row.length; c++) {
var cell = row[c];
- if(cell instanceof math.Complex) {
+ if(cell instanceof math.Complex || ((typeof cell == "object") && ((cell.mathjs && cell.mathjs == "Complex") || (cell.type && cell.type == "Complex")))) {
return true;
}
}
} else {
- if(row instanceof math.Complex) {
+ if(row instanceof math.Complex || ((typeof row == "object") && ((row.mathjs && row.mathjs == "Complex") || (row.type && row.type == "Complex")))) {
return true;
}
}
@@ -3420,6 +3420,7 @@ QuantumCircuit.prototype.isEmptyPlace = function(col, wires, usingCregs) {
for(var wire = minWire; wire <= maxWire; wire++) {
if(!this.isEmptyCell(col, wire)) {
allEmpty = false;
+ break;
}
}
@@ -3444,6 +3445,7 @@ QuantumCircuit.prototype.lastNonEmptyPlace = function(wires, usingCregs) {
for(var wire = minWire; wire <= maxWire; wire++) {
if(!this.isEmptyCell(col, wire)) {
allEmpty = false;
+ break;
}
}
}
@@ -4121,8 +4123,8 @@ QuantumCircuit.prototype.chanceMap = function() {
};
-function binStr(i, len) {
- var bin = i.toString(2);
+function binStr(n, len) {
+ var bin = n.toString(2);
while(bin.length < len) {
bin = "0" + bin;
}
@@ -4130,6 +4132,11 @@ function binStr(i, len) {
}
+function reverseBitwise(n, len) {
+ return parseInt(binStr(n, len).split("").reverse().join(""), 2);
+}
+
+
QuantumCircuit.prototype.resetQubit = function(wire, value) {
var U = [
[0, 0],
@@ -7455,6 +7462,7 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
var centerX = gateX + (options.cellWidth / 2);
var paramsStr = "";
+ var paramsCount = 0;
for(var paramName in gate.options.params) {
if(paramsStr) {
paramsStr += ", ";
@@ -7470,6 +7478,11 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
}
paramsStr += paramVal;
+ paramsCount++;
+ }
+
+ if(paramsStr.length > 26) {
+ paramsStr = "(" + paramsCount + " params)";
}
svg += "" + paramsStr + "";
}
@@ -7696,7 +7709,7 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
if(options.customGate) {
initSymbol = qubitLetter(wire, numRows);
}
- svg += "|" + initSymbol + "⟩";
+ svg += "|" + initSymbol + "⟩";
svg += "";
svg += "q" + wire + "";
}
@@ -12436,7 +12449,7 @@ QuantumCircuit.prototype.continue = function() {
});
};
-QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockSize) {
+QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockSize, reverseBits) {
var state = [];
var numAmplitudes = this.numAmplitudes();
@@ -12446,7 +12459,13 @@ QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockS
var count = 0;
for(var i = 0; i < numAmplitudes; i++) {
- var amplitude = math.round(this.state[i] || math.complex(0, 0), 14);
+ var ampIndex = i;
+ if(reverseBits) {
+ ampIndex = reverseBitwise(i, this.numQubits);
+ }
+
+ var amplitude = math.round(this.state[ampIndex] || math.complex(0, 0), 14);
+
if(!onlyPossible || (amplitude.re || amplitude.im)) {
if(count >= skipItems) {
var indexBinStr = i.toString(2);
@@ -12485,7 +12504,7 @@ QuantumCircuit.prototype.stateAsArray = function(onlyPossible, skipItems, blockS
return state;
};
-QuantumCircuit.prototype.stateAsSimpleArray = function() {
+QuantumCircuit.prototype.stateAsSimpleArray = function(reverseBits) {
var numAmplitudes = this.numAmplitudes();
if(!this.state) {
@@ -12494,7 +12513,12 @@ QuantumCircuit.prototype.stateAsSimpleArray = function() {
var state = [];
for(var i = 0; i < numAmplitudes; i++) {
- state.push(math.round(this.state[i] || math.complex(0, 0), 14));
+ var ampIndex = i;
+ if(reverseBits) {
+ ampIndex = reverseBitwise(i, this.numQubits);
+ }
+
+ state.push(math.round(this.state[ampIndex] || math.complex(0, 0), 14));
}
return state;
};