┌────┐\n", "q_0: ┤0 ├\n", " │ │\n", "q_1: ┤1 ├\n", " │ │\n", "q_2: ┤2 F ├\n", " │ │\n", "q_3: ┤3 ├\n", " │ │\n", "q_4: ┤4 ├\n", " └────┘" ], "text/plain": [ " ┌────┐\n", "q_0: ┤0 ├\n", " │ │\n", "q_1: ┤1 ├\n", " │ │\n", "q_2: ┤2 F ├\n", " │ │\n", "q_3: ┤3 ├\n", " │ │\n", "q_4: ┤4 ├\n", " └────┘" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fixed_income._objective.draw()" ] }, { "cell_type": "code", "execution_count": 8, "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": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fixed_income_circ = QuantumCircuit(fixed_income._objective.num_qubits)\n", "\n", "# load probability distribution\n", "fixed_income_circ.append(u, range(u.num_qubits))\n", "\n", "# apply function\n", "fixed_income_circ.append(fixed_income._objective, range(fixed_income._objective.num_qubits))\n", "\n", "fixed_income_circ.draw()" ] }, { "cell_type": "code", "execution_count": 9, "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", "# construct amplitude estimation\n", "problem = fixed_income.to_estimation_problem()\n", "\n", "ae = IterativeAmplitudeEstimation(\n", " epsilon_target=epsilon, alpha=alpha, sampler=Sampler(run_options={\"shots\": 100, \"seed\": 75})\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.292025Z", "start_time": "2020-07-13T23:39:30.882045Z" } }, "outputs": [], "source": [ "result = ae.estimate(problem)" ] }, { "cell_type": "code", "execution_count": 11, "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.3437\n", "Confidence interval:\t[2.3101, 2.3772]\n" ] } ], "source": [ "conf_int = np.array(result.confidence_interval_processed)\n", "print(\"Exact value: \\t%.4f\" % exact_value)\n", "print(\"Estimated value: \\t%.4f\" % (fixed_income.interpret(result)))\n", "print(\"Confidence interval:\\t[%.4f, %.4f]\" % tuple(conf_int))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.845834Z", "start_time": "2020-07-13T23:39:53.687281Z" } }, "outputs": [ { "data": { "text/html": [ "
Software | Version |
---|---|
qiskit | None |
qiskit-terra | 0.45.0.dev0+c626be7 |
qiskit_finance | 0.4.0 |
qiskit_algorithms | 0.2.0 |
qiskit_ibm_provider | 0.6.1 |
qiskit_optimization | 0.6.0 |
qiskit_aer | 0.12.0 |
System information | |
Python version | 3.9.7 |
Python compiler | GCC 7.5.0 |
Python build | default, Sep 16 2021 13:09:58 |
OS | Linux |
CPUs | 2 |
Memory (Gb) | 5.778430938720703 |
Fri Aug 18 16:21:18 2023 EDT |
© Copyright IBM 2017, 2023.
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.