diff --git a/src/gates/AmplitudeDisplay.js b/src/gates/AmplitudeDisplay.js index d76795ce..3068f9d9 100644 --- a/src/gates/AmplitudeDisplay.js +++ b/src/gates/AmplitudeDisplay.js @@ -131,7 +131,9 @@ function processOutputs(span, pixelGroups, circuitDefinition) { let incoherentUnity = 0; for (let i = 0; i < n; i++) { incoherentUnity += rawIncoherentKetPixels[i]; - incoherentKetPixels[i << 1] = Math.sqrt(rawIncoherentKetPixels[i]); + } + for (let i = 0; i < n; i++) { + incoherentKetPixels[i << 1] = Math.sqrt(rawIncoherentKetPixels[i] / incoherentUnity); } if (isNaN(incoherentUnity) || incoherentUnity < 0.000001) { return { diff --git a/test/gates/AmplitudeDisplay.test.js b/test/gates/AmplitudeDisplay.test.js index da0b773f..c982125c 100644 --- a/test/gates/AmplitudeDisplay.test.js +++ b/test/gates/AmplitudeDisplay.test.js @@ -229,3 +229,15 @@ suite.testUsingWebGL("AmplitudesDisplayIncoherent_hadamard", () => { ]); assertThat(out.displays[0].data.coherence_measure).isLessThan(0.85); }); + +suite.testUsingWebGL("AmplitudesDisplayIncoherent_conditioned", () => { + let stats = CircuitStats.fromCircuitAtTime( + Serializer.fromJson(CircuitDefinition, {"cols":[[1,"•","Z"],["•","Amps1"]],"init":["+","+","+"]}), + 0); + let out = stats.toReadableJson(); + assertThat(out.displays[0].data.incoherentKet).isApproximatelyEqualTo([ + Math.sqrt(0.5), + Math.sqrt(0.5), + ]); + assertThat(out.displays[0].data.coherence_measure).isLessThan(0.85); +});