Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59b4a9c

Browse files
add SWAP test function
1 parent 0d97b1a commit 59b4a9c

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

‎bloch_angles_estimation.ipynb

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,56 @@
473473
"execution_count": null,
474474
"metadata": {},
475475
"outputs": [],
476-
"source": []
476+
"source": [
477+
"def one_qubit_state_swap_test(qubit_1, qubit_2, auxiliary_qubit, circuit, backend, shots):\n",
478+
" \"\"\"\n",
479+
" SWAP test on two one qubit states\n",
480+
" :param qubit_1: the first qubit in |psi_1> (pure) state\n",
481+
" :param qubit_2: the second qubit in |psi_2> (pure) state\n",
482+
" :param auxiliary_qubit: the auxiliary qubit for SWAP test\n",
483+
" (the qubit that will be measured at the end)\n",
484+
" :param circuit: The circuit where all mentioned above qubits are defined\n",
485+
" :return: returns |<psi_1|psi_2>|^2\n",
486+
" \"\"\"\n",
487+
" if len(circuit.cregs) != 0:\n",
488+
" raise NotImplementedError(\"Circuit should not have classical registers, because that case is not implemented.\")\n",
489+
"\n",
490+
" classical_register = ClassicalRegister(1)\n",
491+
" swap_circuit = QuantumCircuit(classical_register)\n",
492+
"\n",
493+
" for qreg in circuit.qregs:\n",
494+
" swap_circuit.add_register(qreg)\n",
495+
" \n",
496+
" swap_circuit += circuit\n",
497+
" \n",
498+
" # main part\n",
499+
" swap_circuit.h(auxillary_qubits[0])\n",
500+
" swap_circuit.cswap(auxiliary_qubit, qubit_1, qubit_2)\n",
501+
" swap_circuit.h(auxillary_qubits[0])\n",
502+
" swap_circuit.measure(auxiliary_qubit, classical_register[0])\n",
503+
"\n",
504+
" counts = execute(swap_circuit, backend, shots=shots).result().get_counts()\n",
505+
" \n",
506+
" return z_expectation_from_counts(counts, 0, shots)"
507+
]
508+
},
509+
{
510+
"cell_type": "markdown",
511+
"metadata": {},
512+
"source": [
513+
"Now let's apply sequence of random gates to a qubit and measure its Bloch angles. After finding the the Bloch angles we will use the same state obtained with the same gate sequence and compare its state with another qubit that will use the estimated Bloch angles. Random gates will not allow us straigforwardly estimate the Bloch angles and hence the Bloch angles are not given us in this problem as it was previously. We can either multiply to each other all matrices that correspond to the gates and try to estimate mathematically the Bloch angles or we can do it in the quantum way with SWAP test. If we have estimated right angles then the output of the SWAP test should be 1ドル$."
514+
]
515+
},
516+
{
517+
"cell_type": "code",
518+
"execution_count": null,
519+
"metadata": {},
520+
"outputs": [],
521+
"source": [
522+
"random_gate_number = 20\n",
523+
"\n",
524+
"quantum_register = QuantumRegister"
525+
]
477526
}
478527
],
479528
"metadata": {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /