Skip to content

Commit

Permalink
Fix conditional incoherent amplitude displays not normalizing magnitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Jun 8, 2019
1 parent 69373f5 commit 5332bce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gates/AmplitudeDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions test/gates/AmplitudeDisplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 5332bce

Please sign in to comment.