quantastica / quantum-circuit

Quantum Circuit Simulator implemented in JavaScript
MIT License
243 stars 47 forks source link

Probabilities can be truncated to 0.00000% in stateAsString(true) #86

Open DanBlackwell opened 2 months ago

DanBlackwell commented 2 months ago

Not necessarily an issue - perhaps an enhancement though. Due to the truncation (or maybe rounding - haven't looked behind the scenes) some probabilities (as well as vector values) for viable states end up being output as 0.

Example program:

const QuantumCircuit = require('quantum-circuit');

let qc = new QuantumCircuit();
let qasm = "OPENQASM 2.0;\n" +
           "include \"qelib1.inc\";\n" +
           "qreg r1[1];\n" +
           "rx(0.0000000001) r1;\n";

qc.importQASM(qasm, (error) => {
    qc.run();
    console.log(qc.stateAsString(true));
})

Output:

 1.00000000+0.00000000i|0>  100.00000%
 0.00000000+0.00000000i|1>    0.00000%