\n", "q_0: ───────────────────■──────────────────────────────────────────────────\n", " │ \n", "q_1: ───────────────────┼─────────────■────────────────────────────────────\n", " │ │ \n", "q_2: ───────────────────┼─────────────┼─────────────■──────────────────────\n", " │ │ │ \n", "q_3: ───────────────────┼─────────────┼─────────────┼─────────────■────────\n", " ┌───────────┐┌─────┴──────┐┌─────┴──────┐┌─────┴─────┐┌──────┴───────┐\n", "q_4: ┤ RY(9π/16) ├┤ RY(-π/216) ├┤ RY(-π/108) ├┤ RY(-π/27) ├┤ RY(-0.23271) ├\n", " └───────────┘└────────────┘└────────────┘└───────────┘└──────────────┘" ], "text/plain": [ " \n", "q_0: ───────────────────■──────────────────────────────────────────────────\n", " │ \n", "q_1: ───────────────────┼─────────────■────────────────────────────────────\n", " │ │ \n", "q_2: ───────────────────┼─────────────┼─────────────■──────────────────────\n", " │ │ │ \n", "q_3: ───────────────────┼─────────────┼─────────────┼─────────────■────────\n", " ┌───────────┐┌─────┴──────┐┌─────┴──────┐┌─────┴─────┐┌──────┴───────┐\n", "q_4: ┤ RY(9π/16) ├┤ RY(-π/216) ├┤ RY(-π/108) ├┤ RY(-π/27) ├┤ RY(-0.23271) ├\n", " └───────────┘└────────────┘└────────────┘└───────────┘└──────────────┘" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fixed_income.draw()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
┌───────┐┌────┐\n", "q_0: ┤0 ├┤0 ├\n", " │ ││ │\n", "q_1: ┤1 ├┤1 ├\n", " │ P(X) ││ │\n", "q_2: ┤2 ├┤2 F ├\n", " │ ││ │\n", "q_3: ┤3 ├┤3 ├\n", " └───────┘│ │\n", "q_4: ─────────┤4 ├\n", " └────┘" ], "text/plain": [ " ┌───────┐┌────┐\n", "q_0: ┤0 ├┤0 ├\n", " │ ││ │\n", "q_1: ┤1 ├┤1 ├\n", " │ P(X) ││ │\n", "q_2: ┤2 ├┤2 F ├\n", " │ ││ │\n", "q_3: ┤3 ├┤3 ├\n", " └───────┘│ │\n", "q_4: ─────────┤4 ├\n", " └────┘" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "state_preparation = QuantumCircuit(fixed_income.num_qubits)\n", "\n", "# load probability distribution\n", "state_preparation.append(u, range(u.num_qubits))\n", "\n", "# apply function\n", "state_preparation.append(fixed_income, range(fixed_income.num_qubits))\n", "\n", "state_preparation.draw()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:30.566677Z", "start_time": "2020-07-13T23:39:30.561554Z" } }, "outputs": [], "source": [ "# set target precision and confidence level\n", "epsilon = 0.01\n", "alpha = 0.05\n", "\n", "# set objective qubit\n", "objective = u.num_qubits\n", "\n", "# construct amplitude estimation \n", "ae = IterativeAmplitudeEstimation(epsilon=epsilon, alpha=alpha, \n", " state_preparation=state_preparation,\n", " objective_qubits=[objective],\n", " post_processing=fixed_income.post_processing)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.292025Z", "start_time": "2020-07-13T23:39:30.882045Z" } }, "outputs": [], "source": [ "result = ae.run(quantum_instance=Aer.get_backend('qasm_simulator'), shots=100)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.298201Z", "start_time": "2020-07-13T23:39:53.294221Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exact value: \t2.1942\n", "Estimated value: \t2.3404\n", "Confidence interval:\t[2.3094, 2.3714]\n" ] } ], "source": [ "conf_int = np.array(result['confidence_interval'])\n", "print('Exact value: \\t%.4f' % exact_value)\n", "print('Estimated value: \\t%.4f' % (result['estimation']))\n", "print('Confidence interval:\\t[%.4f, %.4f]' % tuple(conf_int))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.845834Z", "start_time": "2020-07-13T23:39:53.687281Z" } }, "outputs": [ { "data": { "text/html": [ "
Qiskit Software | Version |
---|---|
Qiskit | 0.23.3 |
Terra | 0.16.2 |
Aer | 0.7.3 |
Ignis | 0.5.1 |
Aqua | 0.8.1 |
IBM Q Provider | 0.11.1 |
System information | |
Python | 3.8.5 (default, Sep 4 2020, 07:30:14) \n", "[GCC 7.3.0] |
OS | Linux |
CPUs | 2 |
Memory (Gb) | 3.736370086669922 |
Thu Jan 28 13:33:57 2021 IST |
© Copyright IBM 2017, 2021.
This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.