|
1304 | 1304 | "show_call_graph(linear_combination_block_encoding_g)\n",
|
1305 | 1305 | "show_counts_sigma(linear_combination_block_encoding_sigma)"
|
1306 | 1306 | ]
|
| 1307 | + }, |
| 1308 | + { |
| 1309 | + "cell_type": "markdown", |
| 1310 | + "id": "e36b6098", |
| 1311 | + "metadata": { |
| 1312 | + "cq.autogen": "SparseMatrix.bloq_doc.md" |
| 1313 | + }, |
| 1314 | + "source": [ |
| 1315 | + "## `SparseMatrix`\n", |
| 1316 | + "Block encoding of a sparse-access matrix.\n", |
| 1317 | + "\n", |
| 1318 | + "Given row, column, and entry oracles $O_r$, $O_c$, and $O_A$ for an $s$-sparse matrix\n", |
| 1319 | + "$A \\in \\mathbb{C}^{2^n \\times 2^n}$, i.e. one where each row / column has exactly $s$ non-zero\n", |
| 1320 | + "entries, computes a $(s, n+1, \\epsilon)$-block encoding of $A$ as follows:\n", |
| 1321 | + "```\n", |
| 1322 | + " ┌────┐ ┌────┐\n", |
| 1323 | + " |0> ─┤ ├─ |0> ─────────────┤ ├───────────────\n", |
| 1324 | + " │ │ ┌──┐ │ │ ┌──┐\n", |
| 1325 | + " │ U │ = │ n│ ┌────┐ │ O │ ┌────┐ │ n│\n", |
| 1326 | + "|0^n> ─┤ A ├─ |0^n> ─┤H ├─┤ ├─┤ A ├─X─┤ ├─┤H ├─\n", |
| 1327 | + " │ │ └──┘ │ O │ │ │ │ │ O* │ └──┘\n", |
| 1328 | + "|Psi> ─┤ ├─ |Psi> ──────┤ c ├─┤ ├─X─┤ r ├──────\n", |
| 1329 | + " └────┘ └────┘ └────┘ └────┘\n", |
| 1330 | + "```\n", |
| 1331 | + "\n", |
| 1332 | + "To encode a matrix of irregular dimension, the matrix should first be embedded into one of\n", |
| 1333 | + "dimension $2^n \\times 2^n$ for suitable $n$.\n", |
| 1334 | + "To encode a matrix where each row / column has at most $s$ non-zero entries, some zeroes should\n", |
| 1335 | + "be treated as if they were non-zero so that each row / column has exactly $s$ non-zero entries.\n", |
| 1336 | + "\n", |
| 1337 | + "#### Parameters\n", |
| 1338 | + " - `row_oracle`: The row oracle $O_r$. See `RowColumnOracle` for definition.\n", |
| 1339 | + " - `col_oracle`: The column oracle $O_c$. See `RowColumnOracle` for definition.\n", |
| 1340 | + " - `entry_oracle`: The entry oracle $O_A$. See `EntryOracle` for definition.\n", |
| 1341 | + " - `eps`: The precision of the block encoding. \n", |
| 1342 | + "\n", |
| 1343 | + "#### Registers\n", |
| 1344 | + " - `system`: The system register.\n", |
| 1345 | + " - `ancilla`: The ancilla register.\n", |
| 1346 | + " - `resource`: The resource register (present only if bitsize > 0). \n", |
| 1347 | + "\n", |
| 1348 | + "#### References\n", |
| 1349 | + " - [Lecture Notes on Quantum Algorithms for Scientific Computation]( https://arxiv.org/pdf/2201.08309). Lin Lin (2022). Ch. 6.5.\n" |
| 1350 | + ] |
| 1351 | + }, |
| 1352 | + { |
| 1353 | + "cell_type": "code", |
| 1354 | + "execution_count": null, |
| 1355 | + "id": "87710c02", |
| 1356 | + "metadata": { |
| 1357 | + "cq.autogen": "SparseMatrix.bloq_doc.py" |
| 1358 | + }, |
| 1359 | + "outputs": [], |
| 1360 | + "source": [ |
| 1361 | + "from qualtran.bloqs.block_encoding import SparseMatrix" |
| 1362 | + ] |
| 1363 | + }, |
| 1364 | + { |
| 1365 | + "cell_type": "markdown", |
| 1366 | + "id": "8b9bd4f0", |
| 1367 | + "metadata": { |
| 1368 | + "cq.autogen": "SparseMatrix.example_instances.md" |
| 1369 | + }, |
| 1370 | + "source": [ |
| 1371 | + "### Example Instances" |
| 1372 | + ] |
| 1373 | + }, |
| 1374 | + { |
| 1375 | + "cell_type": "code", |
| 1376 | + "execution_count": null, |
| 1377 | + "id": "6ad71b09", |
| 1378 | + "metadata": { |
| 1379 | + "cq.autogen": "SparseMatrix.sparse_matrix_block_encoding" |
| 1380 | + }, |
| 1381 | + "outputs": [], |
| 1382 | + "source": [ |
| 1383 | + "from qualtran.bloqs.block_encoding.sparse_matrix import (\n", |
| 1384 | + " UniformEntryOracle,\n", |
| 1385 | + " UniformRowColumnOracle,\n", |
| 1386 | + ")\n", |
| 1387 | + "\n", |
| 1388 | + "row_oracle = UniformRowColumnOracle(n=2, num_nonzero=4)\n", |
| 1389 | + "col_oracle = UniformRowColumnOracle(n=2, num_nonzero=4)\n", |
| 1390 | + "entry_oracle = UniformEntryOracle(n=2, entry=0.3)\n", |
| 1391 | + "sparse_matrix_block_encoding = SparseMatrix(row_oracle, col_oracle, entry_oracle, eps=0)" |
| 1392 | + ] |
| 1393 | + }, |
| 1394 | + { |
| 1395 | + "cell_type": "markdown", |
| 1396 | + "id": "ca16f4df", |
| 1397 | + "metadata": { |
| 1398 | + "cq.autogen": "SparseMatrix.graphical_signature.md" |
| 1399 | + }, |
| 1400 | + "source": [ |
| 1401 | + "#### Graphical Signature" |
| 1402 | + ] |
| 1403 | + }, |
| 1404 | + { |
| 1405 | + "cell_type": "code", |
| 1406 | + "execution_count": null, |
| 1407 | + "id": "6c5da6eb", |
| 1408 | + "metadata": { |
| 1409 | + "cq.autogen": "SparseMatrix.graphical_signature.py" |
| 1410 | + }, |
| 1411 | + "outputs": [], |
| 1412 | + "source": [ |
| 1413 | + "from qualtran.drawing import show_bloqs\n", |
| 1414 | + "show_bloqs([sparse_matrix_block_encoding],\n", |
| 1415 | + " ['`sparse_matrix_block_encoding`'])" |
| 1416 | + ] |
| 1417 | + }, |
| 1418 | + { |
| 1419 | + "cell_type": "markdown", |
| 1420 | + "id": "847bacb4", |
| 1421 | + "metadata": { |
| 1422 | + "cq.autogen": "SparseMatrix.call_graph.md" |
| 1423 | + }, |
| 1424 | + "source": [ |
| 1425 | + "### Call Graph" |
| 1426 | + ] |
| 1427 | + }, |
| 1428 | + { |
| 1429 | + "cell_type": "code", |
| 1430 | + "execution_count": null, |
| 1431 | + "id": "42070c26", |
| 1432 | + "metadata": { |
| 1433 | + "cq.autogen": "SparseMatrix.call_graph.py" |
| 1434 | + }, |
| 1435 | + "outputs": [], |
| 1436 | + "source": [ |
| 1437 | + "from qualtran.resource_counting.generalizers import ignore_split_join\n", |
| 1438 | + "sparse_matrix_block_encoding_g, sparse_matrix_block_encoding_sigma = sparse_matrix_block_encoding.call_graph(max_depth=1, generalizer=ignore_split_join)\n", |
| 1439 | + "show_call_graph(sparse_matrix_block_encoding_g)\n", |
| 1440 | + "show_counts_sigma(sparse_matrix_block_encoding_sigma)" |
| 1441 | + ] |
1307 | 1442 | }
|
1308 | 1443 | ],
|
1309 | 1444 | "metadata": {
|
|
0 commit comments