Spaces:
Running
Running
File size: 2,040 Bytes
01cde5b 24586ae 01cde5b 24586ae 01cde5b 24586ae 01cde5b |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
<!doctype html>
<html>
<head>
<title>VQE Hydrogen Molecule Ground State</title>
</head>
<body>
<h5>VQE Hydrogen Molecule Ground State</h5>
<button type="button" id="run-vqe">Run VQE</button>
<br />
<br />
<div id="drawing"></div>
<pre><code id="output"></code></pre>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/quantum-circuit"></script>
<script>
var circuit = new QuantumCircuit();
function runVQE() {
clearLog();
circuit.init();
// Define the VQE circuit for H₂ ground state estimation
// Using a minimal STO-3G basis set
circuit.addGate("h", 0, 0); // Apply Hadamard to qubit 0
circuit.addGate("h", 1, 0); // Apply Hadamard to qubit 1
// Parameterized rotations for VQE ansatz
circuit.addGate("rx", 2, 0, { params: { theta: Math.PI / 4 } });
circuit.addGate("rx", 3, 1, { params: { theta: Math.PI / 4 } });
// Entanglement between qubits
circuit.addGate("cx", 4, [0, 1]);
// Simulate the circuit
circuit.run();
// Log the results to the output
LogOutput();
ShowCircuit();
// Print results to the screen
const outputElement = document.getElementById("output");
outputElement.innerText = circuit.stateAsString(true);
}
function clearLog() {
document.getElementById("output").innerText = "";
}
function Log(s) {
document.getElementById("output").innerText += "\n" + s;
}
function LogOutput() {
Log("Final state:");
Log("------------");
Log(circuit.stateAsString(true));
Log("");
}
function ShowCircuit() {
var drawing = document.getElementById("drawing");
drawing.innerHTML = circuit.exportSVG(true);
}
// Ensure the button click event is properly connected
$(document).ready(function () {
$("#run-vqe").off("click").on("click", function () {
runVQE();
});
});
</script>
</body>
</html>
|