microsoft / qsharp

Azure Quantum Development Kit, including the Q# programming language, resource estimator, and Quantum Katas
https://microsoft.github.io/qsharp/
MIT License
366 stars 73 forks source link

Fix normalization math in `DumpRegister` #1608

Closed swernli closed 3 weeks ago

swernli commented 3 weeks ago

This fixes a bug in the way the wave function was produced for calls to DumpRegister, specifically because the calculation needs to use the sum of the squares of the normalization of each amplitude rather than just the sum of the normalization value itself. This ensures the amplitudes output by DumpRegister correctly sum to 1.

Output before fix: image

Output after fix: image

github-actions[bot] commented 3 weeks ago

Benchmark for 8a2be1e

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Array append evaluation | 336.2±2.80µs | **332.4±1.77µs** | **-1.13%** | | Array literal evaluation | 187.3±2.09µs | **184.2±2.17µs** | **-1.66%** | | Array update evaluation | 418.5±9.68µs | **411.7±4.79µs** | **-1.62%** | | Core + Standard library compilation | 26.2±2.44ms | **23.5±1.66ms** | **-10.31%** | | Deutsch-Jozsa evaluation | 5.1±0.04ms | 5.1±0.15ms | 0.00% | | Large file parity evaluation | 34.8±0.26ms | 34.9±0.40ms | +0.29% | | Large input file compilation | 16.4±1.49ms | 15.4±1.06ms | -6.10% | | Large input file compilation (interpreter) | 64.8±5.83ms | 62.8±2.62ms | -3.09% | | Large nested iteration | 33.3±0.45ms | 33.2±0.64ms | -0.30% | | Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample | 1685.5±231.69µs | 1644.4±160.95µs | -2.44% | | Perform Runtime Capabilities Analysis (RCA) on large file sample | 9.0±0.54ms | **8.2±0.25ms** | **-8.89%** | | Perform Runtime Capabilities Analysis (RCA) on teleport sample | 1510.0±165.38µs | 1502.6±178.77µs | -0.49% | | Perform Runtime Capabilities Analysis (RCA) on the core and std libraries | 31.0±1.27ms | 30.9±1.18ms | -0.32% | | Teleport evaluation | 89.7±3.79µs | 89.3±5.69µs | -0.45% |
github-actions[bot] commented 3 weeks ago

Benchmark for 16e8139

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Array append evaluation | **332.0±2.09µs** | 338.5±17.69µs | **+1.96%** | | Array literal evaluation | **173.1±8.81µs** | 186.0±1.73µs | **+7.45%** | | Array update evaluation | **408.2±2.99µs** | 417.7±14.92µs | **+2.33%** | | Core + Standard library compilation | 18.7±0.38ms | 18.8±0.46ms | +0.53% | | Deutsch-Jozsa evaluation | 5.1±0.04ms | 5.1±0.12ms | 0.00% | | Large file parity evaluation | **34.0±0.10ms** | 34.2±0.57ms | **+0.59%** | | Large input file compilation | 12.4±0.35ms | 12.3±0.30ms | -0.81% | | Large input file compilation (interpreter) | 46.2±1.31ms | 46.3±1.26ms | +0.22% | | Large nested iteration | **32.5±0.24ms** | 32.8±0.20ms | **+0.92%** | | Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample | 1556.1±36.23µs | 1561.5±32.49µs | +0.35% | | Perform Runtime Capabilities Analysis (RCA) on large file sample | 7.8±0.10ms | 7.8±0.11ms | 0.00% | | Perform Runtime Capabilities Analysis (RCA) on teleport sample | 1415.5±30.04µs | 1424.1±35.33µs | +0.61% | | Perform Runtime Capabilities Analysis (RCA) on the core and std libraries | **28.1±0.20ms** | 28.3±0.35ms | **+0.71%** | | Teleport evaluation | 88.7±3.92µs | 89.0±5.42µs | +0.34% |