-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathw_state_qasm.js
62 lines (48 loc) · 1.27 KB
/
w_state_qasm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const QuantumCircuit = require("../../lib/quantum-circuit.js");
var input = "";
input += "// Name of Experiment: W-state v1\n";
input += "OPENQASM 2.0;\n";
input += "include \"qelib1.inc\";\n";
input += "qreg q[3];\n";
input += "creg c[3];\n";
input += "gate cH a,b {\n";
input += " h b;\n";
input += " sdg b;\n";
input += " cx a,b;\n";
input += " h b;\n";
input += " t b;\n";
input += " cx a,b;\n";
input += " t b;\n";
input += " h b;\n";
input += " s b;\n";
input += " x b;\n";
input += " s a;\n";
input += "}\n";
input += "u3(1.91063,0,0) q[0];\n";
input += "cH q[0],q[1];\n";
input += "ccx q[0],q[1],q[2];\n";
input += "x q[0];\n";
input += "x q[1];\n";
input += "cx q[0],q[1];\n";
input += "measure q[0] -> c[0];\n";
input += "measure q[1] -> c[1];\n";
input += "measure q[2] -> c[2];\n";
var circuit = new QuantumCircuit();
console.log("");
console.log("Importing QASM...");
circuit.importQASM(input);
console.log("");
console.log("Calculating...");
circuit.run();
console.log("");
console.log("Final amplitudes:");
circuit.print(true);
console.log("");
console.log("Angles:");
console.log(circuit.angles());
console.log("");
console.log("Probabilities:");
console.log(circuit.probabilities());
console.log("");
console.log("Measured:");
console.log(circuit.measureAll());