|
<!doctype html> |
|
<html> |
|
<head> |
|
<title>Time Evolution of a Qubit Under a Z Hamiltonian</title> |
|
</head> |
|
|
|
<body> |
|
<h5>Time Evolution of a Qubit Under a Z Hamiltonian</h5> |
|
<button type="button" id="run-time-evolution">Run Time Evolution</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 runTimeEvolution() { |
|
clearLog(); |
|
|
|
circuit.init(); |
|
|
|
|
|
|
|
const time = Math.PI / 4; |
|
|
|
|
|
circuit.addGate("h", 0, 0); |
|
|
|
|
|
circuit.addGate("rz", 1, 0, { params: { phi: -2 * time } }); |
|
|
|
|
|
circuit.run(); |
|
|
|
|
|
LogOutput(); |
|
ShowCircuit(); |
|
|
|
|
|
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); |
|
} |
|
|
|
|
|
$(document).ready(function () { |
|
$("#run-time-evolution").off("click").on("click", function () { |
|
runTimeEvolution(); |
|
}); |
|
}); |
|
</script> |
|
</body> |
|
</html> |