Skip to content

Commit

Permalink
Use same NaN condition for amplitude display as for chance display
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Mar 24, 2019
1 parent 3ad0ce5 commit 5cdbbaa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/gates/AmplitudeDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function amplitudeDisplayStatTextures(stateKet, controls, controlsTexture, range
* @param {!int} span
* @param {!Array.<!Float32Array>} pixelGroups
* @param {!CircuitDefinition} circuitDefinition
* @returns {!{quality: !float, ket: undefined|!Matrix, phaseLockIndex: undefined|!int}}
* @returns {!{quality: !number, ket: !Matrix, phaseLockIndex: !int,incoherentKet: !Matrix}}
*/
function processOutputs(span, pixelGroups, circuitDefinition) {
let [ketPixels, qualityPixels, rawIncoherentKetPixels] = pixelGroups;
Expand All @@ -128,9 +128,19 @@ function processOutputs(span, pixelGroups, circuitDefinition) {
unity += e*e;
}
let incoherentKetPixels = new Float32Array(w * h * 2);
let incoherentUnity = 0;
for (let i = 0; i < n; i++) {
incoherentUnity += rawIncoherentKetPixels[i];
incoherentKetPixels[i << 1] = Math.sqrt(rawIncoherentKetPixels[i]);
}
if (isNaN(unity) || unity < 0.000001) {
return {
quality: 0.0,
ket: Matrix.zero(w, h).times(NaN),
phaseLockIndex: 0,
incoherentKet: Matrix.zero(w, h).times(NaN),
};
}

let phaseIndex = span === circuitDefinition.numWires ? undefined : _processOutputs_pickPhaseLockIndex(ketPixels);
let phase = phaseIndex === undefined ? 0 : Math.atan2(ketPixels[phaseIndex*2+1], ketPixels[phaseIndex*2]);
Expand Down Expand Up @@ -322,7 +332,7 @@ function paintErrorIfPresent(args, indicatorAlpha) {
}

/**
* @param {!{quality: !float, ket: undefined|!Matrix, phaseLockIndex: undefined|!int}} customStats
* @param {!{quality: !number, ket: !Matrix, phaseLockIndex: !int,incoherentKet: !Matrix}} customStats
*/
function customStatsToJsonData(customStats) {
let {quality, ket, phaseLockIndex, incoherentKet} = customStats;
Expand Down

0 comments on commit 5cdbbaa

Please sign in to comment.