From 7dd1f05b3e4af47564fd2d2b2c8ad4255f86795c Mon Sep 17 00:00:00 2001 From: perak Date: Mon, 13 Feb 2023 22:19:59 +0100 Subject: [PATCH] Minor fixes --- .DS_Store | Bin 0 -> 6148 bytes lib/.DS_Store | Bin 0 -> 6148 bytes lib/quantum-circuit.js | 42 ++++++++++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 .DS_Store create mode 100644 lib/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..44e0be8a294204a1cb221e0169d979bc808c1219 GIT binary patch literal 6148 zcmeHK%}T>S5Z>*NO(;SRDjpZS7Hn-jh?fxS3mDOZN=-=7V9ZLB*h4Ags4wKB_&m<+ zZl$%_qez{B*>87tCSksWogKy)_ll^)n8O&eKoKi84BrUuqb^CsSZaVApOHO69CA!p zwia2=jis%|FHL9Zn2Gs%p;x$qU z%(0ii7-7&gSZahF5UxW3btpG22G`+W7sk&uSZdVajGN|zn>TaQp>Xwfc)n2XjJq0X zBnF6qMFy&R>0tdo{ki{N45Ae=Kn$!E1H9Jv`yQlZYU@&RSZf97Ehq~5l^Q=oV4_Mf f_+lyE1yureffGR2V5t!-AaoH>G|)f{{3-(<`!I!h literal 0 HcmV?d00001 diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..88382841cd745daf74fe149de9bcc76115f095f6 GIT binary patch literal 6148 zcmeHK!Ab)$5S_HuZYe?!Djow~3%0f%#LH6a54fTSmAcCoU0gS{yLAtxut)tNKgI8H zCP~Fod+;JsW?=FrlbH>9SuzO#h~6Y@12h1@K_x8Ju=zn~oODS_)IkiD! zcRD>fY|7TGDW~mjx7(D*oz84lb9VL*PR<99@l&E+4WR=6JuO=n=kSKcinYCX<0Mwe zJx0v4=UI%*05iZ0tUm+xRqDd9@i6Kln`lXF?Efxk%ItV>8e#g!%> 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; };