|
473 | 473 | "execution_count": null,
|
474 | 474 | "metadata": {},
|
475 | 475 | "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 | + ] |
477 | 526 | }
|
478 | 527 | ],
|
479 | 528 | "metadata": {
|
|
0 commit comments