|
5 | 5 | "id": "d44fcc7d-37bb-4ecd-997e-a71168e6b8bb", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# Using QSVT for matrix inversion" |
| 8 | + "# Using QSVT for Matrix Inversion" |
9 | 9 | ] |
10 | 10 | }, |
11 | 11 | { |
12 | 12 | "cell_type": "markdown", |
13 | 13 | "id": "824bed94-9040-4bf4-87dc-a0f84dc155dd", |
14 | 14 | "metadata": {}, |
15 | 15 | "source": [ |
16 | | - "In this notebook, we will use the Quantum Singular Value Transformation (QSVT) algorithm to solve the problem of matrix inversion.\n", |
17 | | - "The demo is based on the paper [Grand unification of quantum algorithms](#grand)." |
| 16 | + "This notebook uses the Quantum Singular Value Transformation (QSVT) algorithm to solve the problem of matrix inversion.\n", |
| 17 | + "The demo is based on the [Grand unification of quantum algorithms](#grand) paper." |
18 | 18 | ] |
19 | 19 | }, |
20 | 20 | { |
|
32 | 32 | "id": "df475c3d-8911-47c0-bae2-4ac812858238", |
33 | 33 | "metadata": {}, |
34 | 34 | "source": [ |
35 | | - "We start by defining a specific problem. We can take matrix that is not symmetric, in comparison to the HHL algorithm." |
| 35 | + "We start by defining a specific problem. We can take a matrix that is not symmetric, in comparison to the HHL algorithm." |
36 | 36 | ] |
37 | 37 | }, |
38 | 38 | { |
|
42 | 42 | "tags": [] |
43 | 43 | }, |
44 | 44 | "source": [ |
45 | | - "We will encode $A$ in a larger Unitary matrix. For simplicity, we will just sample a random unitary U_a, and take it's first block as $A$" |
| 45 | + "We encode $A$ in a larger unitary matrix. For simplicity, we just sample a random unitary U_a and take its first block as $A$." |
46 | 46 | ] |
47 | 47 | }, |
48 | 48 | { |
|
95 | 95 | "id": "e988a4aa-158a-4873-a021-e2968e300dd6", |
96 | 96 | "metadata": {}, |
97 | 97 | "source": [ |
98 | | - "Make sure A's singular values are smaller than 1:" |
| 98 | + "Make sure the singular values for A are smaller than 1:" |
99 | 99 | ] |
100 | 100 | }, |
101 | 101 | { |
|
169 | 169 | "id": "11a86ae0-e2d9-4149-a372-c704f9e6c0fa", |
170 | 170 | "metadata": {}, |
171 | 171 | "source": [ |
172 | | - "Calculate the condition number $\\kappa=max(\\frac{1}{\\sigma_i})$" |
| 172 | + "Calculate the condition number $\\kappa=max(\\frac{1}{\\sigma_i})$:" |
173 | 173 | ] |
174 | 174 | }, |
175 | 175 | { |
|
229 | 229 | "id": "9d95795a-c45b-4533-b7e0-2b410b824717", |
230 | 230 | "metadata": {}, |
231 | 231 | "source": [ |
232 | | - "## Now to the quantum part!" |
| 232 | + "## Now for the Quantum Part!" |
233 | 233 | ] |
234 | 234 | }, |
235 | 235 | { |
|
239 | 239 | "tags": [] |
240 | 240 | }, |
241 | 241 | "source": [ |
242 | | - "### Defining the QSVT circuit for the problem" |
| 242 | + "### Defining the QSVT Circuit for the Problem" |
243 | 243 | ] |
244 | 244 | }, |
245 | 245 | { |
246 | 246 | "cell_type": "markdown", |
247 | 247 | "id": "8be8918a-b752-480e-ae63-9fe39151d23a", |
248 | 248 | "metadata": {}, |
249 | 249 | "source": [ |
250 | | - "We start with the general qsvt framework definition. It accepts a unitary which block-encode a matrix together with projector-controlled-cnot functions which identify the block in which the matrix is encoded.\n", |
| 250 | + "We start with the general QSVT framework definition. It accepts a unitary that block-encodes a matrix together with projector-controlled-cnot functions, which identify the block in which the matrix is encoded.\n", |
251 | 251 | "\n", |
252 | | - "It applies the `qsvt_step` multiple times, iterating over the rotation angles provided which encode the polynomial transformation.\n", |
253 | | - "Notice - The last step is quite tricky and depend on the specific transformation we wish to perform. Here the code is suitable for the matrix-inversion case. Also - we wrap the auxilliary qubit with $H$ gates." |
| 252 | + "It applies the `qsvt_step` multiple times, iterating over the rotation angles provided that encode the polynomial transformation.\n", |
| 253 | + "Note that the last step is quite tricky and depends on the specific transformation we wish to perform. Here the code is suitable for the matrix-inversion case. In addition, we wrap the auxilliary qubit with $H$ gates." |
254 | 254 | ] |
255 | 255 | }, |
256 | 256 | { |
|
353 | 353 | } |
354 | 354 | }, |
355 | 355 | "source": [ |
356 | | - "### Matrix inversion logic\n", |
| 356 | + "### Matrix Inversion Logic\n", |
357 | 357 | "\n", |
358 | | - "Here define the specific use case of the matrix inversion. In this case, both projectors are the same, and expect the block encoded matrix to apply on the states where the first qubit value is $|0\\rangle$, hence:" |
| 358 | + "We define the specific use case of the matrix inversion. In this case, both projectors are the same, and we expect the block-encoded matrix to apply on the states where the first qubit value is $|0\\rangle$:" |
359 | 359 | ] |
360 | 360 | }, |
361 | 361 | { |
|
399 | 399 | "id": "9b9160aa-c9b0-46ff-a29f-214a344610b8", |
400 | 400 | "metadata": {}, |
401 | 401 | "source": [ |
402 | | - "### Get the phase sequence for the inverse function" |
| 402 | + "### Getting the Phase Sequence for the Inverse Function" |
403 | 403 | ] |
404 | 404 | }, |
405 | 405 | { |
|
409 | 409 | "tags": [] |
410 | 410 | }, |
411 | 411 | "source": [ |
412 | | - "Get directly the coef of the sign function, based on the erfc approximation, using the `pyqsp` package:" |
| 412 | + "Get the coefficient of the sign function directly, based on the ERFC approximation, using the `pyqsp` package:" |
413 | 413 | ] |
414 | 414 | }, |
415 | 415 | { |
|
495 | 495 | "id": "2e30167a-ff5a-49f5-bf56-0e505c533a95", |
496 | 496 | "metadata": {}, |
497 | 497 | "source": [ |
498 | | - "#### Adjusting phase conventions" |
| 498 | + "### Adjusting Phase Conventions" |
499 | 499 | ] |
500 | 500 | }, |
501 | 501 | { |
502 | 502 | "cell_type": "markdown", |
503 | 503 | "id": "01809547-4727-4dce-89aa-41a15df3e33a", |
504 | 504 | "metadata": {}, |
505 | 505 | "source": [ |
506 | | - "There conventions by which the `pyqsp` package calculates the the phases are different from the phases we need for this qsvt circuit. The following block takes care for them." |
| 506 | + "The conventions by which the `pyqsp` package calculates the the phases are different from the phases we need for this QSVT circuit. The following block takes care of them." |
507 | 507 | ] |
508 | 508 | }, |
509 | 509 | { |
510 | 510 | "cell_type": "markdown", |
511 | 511 | "id": "8c515575-100b-400e-8d24-9bb8e4ab70e2", |
512 | 512 | "metadata": {}, |
513 | 513 | "source": [ |
514 | | - "As $R(a)=-i*e^{i\\frac{\\pi}{4}Z}W(a)e^{i\\frac{\\pi}{4}Z}$ and we have odd number of rotations, we get an i phase to our polynomial, so we get $Im(P(a))$ instead of the real part. So we will get the result in the $|1\\rangle$ state in the ancilla. However, we can fix it by adding $\\pi/2$ phase to the last or first rotation." |
| 514 | + "As $R(a)=-i*e^{i\\frac{\\pi}{4}Z}W(a)e^{i\\frac{\\pi}{4}Z}$ and we have an odd number of rotations, we get an i phase for our polynomial, so we get $Im(P(a))$ instead of the real part. We receive the result in the $|1\\rangle$ state in the ancilla, which can be fixed by adding a $\\pi/2$ phase to the last or first rotation." |
515 | 515 | ] |
516 | 516 | }, |
517 | 517 | { |
|
542 | 542 | "id": "74588c18-8231-4c0d-8bce-6a70b31edca3", |
543 | 543 | "metadata": {}, |
544 | 544 | "source": [ |
545 | | - "### Using the inversion function to solve linear system - `main` function\n", |
| 545 | + "### Using the Inversion Function to Solve a Linear System\n", |
546 | 546 | "\n", |
547 | | - "The following block defines the `main` function. This is the entry point for the quantum algorithm, which brings all previous parts together.\n", |
| 547 | + "The following block defines the `main` function. This is the entry point for the quantum algorithm, which brings all the previous parts together.\n", |
548 | 548 | "\n", |
549 | | - "Specifically, we will use the function `prepare_amplitudes` for loading the vector $b$ into the quantum state.\n", |
550 | | - "\n", |
551 | | - "Then apply the 'qsvt_inversion`. We use the to the dagger of the unitary $U$ which block encodes $A$, because, using the SVD decomposition:\n", |
| 549 | + "Specifically, we use the `prepare_amplitudes` function to load the $b$ vector into the quantum state. We then apply 'qsvt_inversion`. We use the dagger of the unitary $U$ that block-encodes $A$, because, using the SVD decomposition:\n", |
552 | 550 | "$$\n", |
553 | 551 | "\\begin{align}\n", |
554 | 552 | "A &=W\\Sigma V^\\dagger\\\\\n", |
|
602 | 600 | "id": "f0561842-db43-44d4-8a99-ae088ad082d2", |
603 | 601 | "metadata": {}, |
604 | 602 | "source": [ |
605 | | - "## Synthesizing and Executing the circuit using state-vector simulator, to get $x=A^{-1}b$" |
| 603 | + "## Synthesizing and Executing the Circuit Using a State Vector Simulator" |
| 604 | + ] |
| 605 | + }, |
| 606 | + { |
| 607 | + "cell_type": "markdown", |
| 608 | + "id": "2934c1c7-9aff-4e1a-b497-fbaaeb8d40ad", |
| 609 | + "metadata": {}, |
| 610 | + "source": [ |
| 611 | + "We want to get $x=A^{-1}b$:" |
606 | 612 | ] |
607 | 613 | }, |
608 | 614 | { |
|
643 | 649 | "id": "b96713f1-e21d-48fb-b395-dd892ca4d85d", |
644 | 650 | "metadata": {}, |
645 | 651 | "source": [ |
646 | | - "synthesize the model to a quantum program:" |
| 652 | + "We synthesize the model into a quantum program:" |
647 | 653 | ] |
648 | 654 | }, |
649 | 655 | { |
|
673 | 679 | "id": "f2c6bdcf-12ac-4088-bc5b-291d62339458", |
674 | 680 | "metadata": {}, |
675 | 681 | "source": [ |
676 | | - "Execute on the simulator" |
| 682 | + "We execute it on the simulator:" |
677 | 683 | ] |
678 | 684 | }, |
679 | 685 | { |
|
695 | 701 | "id": "53655a1e-6860-4cf1-9fb5-8d5ee6796cb5", |
696 | 702 | "metadata": {}, |
697 | 703 | "source": [ |
698 | | - "## Post processing" |
| 704 | + "## Postprocessing" |
699 | 705 | ] |
700 | 706 | }, |
701 | 707 | { |
702 | 708 | "cell_type": "markdown", |
703 | 709 | "id": "c33e2a62-a07c-4cd1-bfe0-ab4bff32f604", |
704 | 710 | "metadata": {}, |
705 | 711 | "source": [ |
706 | | - "We will be interested in the projection of the state vector on the states where both the auxilliary qubit and the block qubit are $|0\\rangle$." |
| 712 | + "We are interested in the projection of the state vector on the states where both the auxilliary qubit and the block qubit are $|0\\rangle$:" |
707 | 713 | ] |
708 | 714 | }, |
709 | 715 | { |
|
776 | 782 | "id": "395a1556-bde5-442d-bb38-aa6f95934143", |
777 | 783 | "metadata": {}, |
778 | 784 | "source": [ |
779 | | - "Now compare to the expected solution:" |
| 785 | + "Let's compare it with the expected solution:" |
780 | 786 | ] |
781 | 787 | }, |
782 | 788 | { |
|
0 commit comments