Spaces:
Running
Running
Update index.html
Browse files- index.html +71 -12
index.html
CHANGED
|
@@ -1,19 +1,78 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
-
<
|
| 5 |
-
<meta name="viewport" content="width=device-width" />
|
| 6 |
-
<title>My static Space</title>
|
| 7 |
-
<link rel="stylesheet" href="style.css" />
|
| 8 |
</head>
|
|
|
|
| 9 |
<body>
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
</body>
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
+
<title>VQE Hydrogen Molecule Ground State</title>
|
|
|
|
|
|
|
|
|
|
| 5 |
</head>
|
| 6 |
+
|
| 7 |
<body>
|
| 8 |
+
<h5>VQE Hydrogen Molecule Ground State</h5>
|
| 9 |
+
<button type="button" id="run-vqe">Run VQE</button>
|
| 10 |
+
<br />
|
| 11 |
+
<br />
|
| 12 |
+
<div id="drawing"></div>
|
| 13 |
+
<pre><code id="output"></code></pre>
|
| 14 |
+
|
| 15 |
+
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
| 16 |
+
<script src="https://unpkg.com/quantum-circuit"></script>
|
| 17 |
+
|
| 18 |
+
<script>
|
| 19 |
+
var circuit = new QuantumCircuit();
|
| 20 |
+
|
| 21 |
+
function runVQE() {
|
| 22 |
+
clearLog();
|
| 23 |
+
|
| 24 |
+
circuit.init();
|
| 25 |
+
|
| 26 |
+
// Define the VQE circuit for H₂ ground state estimation
|
| 27 |
+
// Using a minimal STO-3G basis set
|
| 28 |
+
circuit.addGate("h", 0, 0); // Apply Hadamard to qubit 0
|
| 29 |
+
circuit.addGate("h", 1, 0); // Apply Hadamard to qubit 1
|
| 30 |
+
|
| 31 |
+
// Parameterized rotations for VQE ansatz
|
| 32 |
+
circuit.addGate("rx", 2, 0, { params: { theta: Math.PI / 4 } });
|
| 33 |
+
circuit.addGate("rx", 3, 1, { params: { theta: Math.PI / 4 } });
|
| 34 |
+
|
| 35 |
+
// Entanglement between qubits
|
| 36 |
+
circuit.addGate("cx", 4, [0, 1]);
|
| 37 |
+
|
| 38 |
+
// Simulate the circuit
|
| 39 |
+
circuit.run();
|
| 40 |
+
|
| 41 |
+
// Log the results to the output
|
| 42 |
+
LogOutput();
|
| 43 |
+
ShowCircuit();
|
| 44 |
+
|
| 45 |
+
// Print results to the screen
|
| 46 |
+
const outputElement = document.getElementById("output");
|
| 47 |
+
outputElement.innerText = circuit.stateAsString(true);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function clearLog() {
|
| 51 |
+
document.getElementById("output").innerText = "";
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function Log(s) {
|
| 55 |
+
document.getElementById("output").innerText += "\n" + s;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function LogOutput() {
|
| 59 |
+
Log("Final state:");
|
| 60 |
+
Log("------------");
|
| 61 |
+
Log(circuit.stateAsString(true));
|
| 62 |
+
Log("");
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function ShowCircuit() {
|
| 66 |
+
var drawing = document.getElementById("drawing");
|
| 67 |
+
drawing.innerHTML = circuit.exportSVG(true);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// Ensure the button click event is properly connected
|
| 71 |
+
$(document).ready(function () {
|
| 72 |
+
$("#run-vqe").off("click").on("click", function () {
|
| 73 |
+
runVQE();
|
| 74 |
+
});
|
| 75 |
+
});
|
| 76 |
+
</script>
|
| 77 |
</body>
|
| 78 |
</html>
|