|
307 | 307 | }, |
308 | 308 | { |
309 | 309 | "cell_type": "markdown", |
310 | | - "id": "1df2fb29", |
| 310 | + "id": "2813f173", |
311 | 311 | "metadata": { |
312 | | - "cq.autogen": "AddConstantMod.bloq_doc.md" |
| 312 | + "cq.autogen": "AddK.bloq_doc.md" |
313 | 313 | }, |
314 | 314 | "source": [ |
315 | | - "## `AddConstantMod`\n", |
316 | | - "Applies U(add, M)|x> = |(x + add) % M> if x < M else |x>.\n", |
317 | | - "\n", |
318 | | - "Applies modular addition to input register `|x>` given parameters `mod` and `add_val` s.t.\n", |
319 | | - " 1. If integer `x` < `mod`: output is `|(x + add) % M>`\n", |
320 | | - " 2. If integer `x` >= `mod`: output is `|x>`.\n", |
321 | | - "\n", |
322 | | - "This condition is needed to ensure that the mapping of all input basis states (i.e. input\n", |
323 | | - "states |0>, |1>, ..., |2 ** bitsize - 1) to corresponding output states is bijective and thus\n", |
324 | | - "the gate is reversible.\n", |
325 | | - "\n", |
326 | | - "Also supports controlled version of the gate by specifying a per qubit control value as a tuple\n", |
327 | | - "of integers passed as `cvs`." |
328 | | - ] |
329 | | - }, |
330 | | - { |
331 | | - "cell_type": "code", |
332 | | - "execution_count": null, |
333 | | - "id": "5ef2dab4", |
334 | | - "metadata": { |
335 | | - "cq.autogen": "AddConstantMod.bloq_doc.py" |
336 | | - }, |
337 | | - "outputs": [], |
338 | | - "source": [ |
339 | | - "from qualtran.bloqs.arithmetic import AddConstantMod" |
340 | | - ] |
341 | | - }, |
342 | | - { |
343 | | - "cell_type": "markdown", |
344 | | - "id": "ed3f3c05", |
345 | | - "metadata": { |
346 | | - "cq.autogen": "AddConstantMod.example_instances.md" |
347 | | - }, |
348 | | - "source": [ |
349 | | - "### Example Instances" |
350 | | - ] |
351 | | - }, |
352 | | - { |
353 | | - "cell_type": "code", |
354 | | - "execution_count": null, |
355 | | - "id": "195a8047", |
356 | | - "metadata": { |
357 | | - "cq.autogen": "AddConstantMod.add_k_symb" |
358 | | - }, |
359 | | - "outputs": [], |
360 | | - "source": [ |
361 | | - "n, m, k = sympy.symbols('n m k')\n", |
362 | | - "add_k_symb = AddConstantMod(bitsize=n, mod=m, add_val=k)" |
363 | | - ] |
364 | | - }, |
365 | | - { |
366 | | - "cell_type": "code", |
367 | | - "execution_count": null, |
368 | | - "id": "9c3f7fb3", |
369 | | - "metadata": { |
370 | | - "cq.autogen": "AddConstantMod.add_k_small" |
371 | | - }, |
372 | | - "outputs": [], |
373 | | - "source": [ |
374 | | - "add_k_small = AddConstantMod(bitsize=4, mod=7, add_val=1)" |
375 | | - ] |
376 | | - }, |
377 | | - { |
378 | | - "cell_type": "code", |
379 | | - "execution_count": null, |
380 | | - "id": "bdc82bc1", |
381 | | - "metadata": { |
382 | | - "cq.autogen": "AddConstantMod.add_k_large" |
383 | | - }, |
384 | | - "outputs": [], |
385 | | - "source": [ |
386 | | - "add_k_large = AddConstantMod(bitsize=64, mod=500, add_val=23)" |
387 | | - ] |
388 | | - }, |
389 | | - { |
390 | | - "cell_type": "markdown", |
391 | | - "id": "b6885dbb", |
392 | | - "metadata": { |
393 | | - "cq.autogen": "AddConstantMod.graphical_signature.md" |
394 | | - }, |
395 | | - "source": [ |
396 | | - "#### Graphical Signature" |
397 | | - ] |
398 | | - }, |
399 | | - { |
400 | | - "cell_type": "code", |
401 | | - "execution_count": null, |
402 | | - "id": "65773e01", |
403 | | - "metadata": { |
404 | | - "cq.autogen": "AddConstantMod.graphical_signature.py" |
405 | | - }, |
406 | | - "outputs": [], |
407 | | - "source": [ |
408 | | - "from qualtran.drawing import show_bloqs\n", |
409 | | - "show_bloqs([add_k_symb, add_k_small, add_k_large],\n", |
410 | | - " ['`add_k_symb`', '`add_k_small`', '`add_k_large`'])" |
411 | | - ] |
412 | | - }, |
413 | | - { |
414 | | - "cell_type": "markdown", |
415 | | - "id": "1a4bf832", |
416 | | - "metadata": { |
417 | | - "cq.autogen": "AddConstantMod.call_graph.md" |
418 | | - }, |
419 | | - "source": [ |
420 | | - "### Call Graph" |
421 | | - ] |
422 | | - }, |
423 | | - { |
424 | | - "cell_type": "code", |
425 | | - "execution_count": null, |
426 | | - "id": "61f1568e", |
427 | | - "metadata": { |
428 | | - "cq.autogen": "AddConstantMod.call_graph.py" |
429 | | - }, |
430 | | - "outputs": [], |
431 | | - "source": [ |
432 | | - "from qualtran.resource_counting.generalizers import ignore_split_join\n", |
433 | | - "add_k_symb_g, add_k_symb_sigma = add_k_symb.call_graph(max_depth=1, generalizer=ignore_split_join)\n", |
434 | | - "show_call_graph(add_k_symb_g)\n", |
435 | | - "show_counts_sigma(add_k_symb_sigma)" |
436 | | - ] |
437 | | - }, |
438 | | - { |
439 | | - "cell_type": "markdown", |
440 | | - "id": "9449e4e9", |
441 | | - "metadata": { |
442 | | - "cq.autogen": "SimpleAddConstant.bloq_doc.md" |
443 | | - }, |
444 | | - "source": [ |
445 | | - "## `SimpleAddConstant`\n", |
| 315 | + "## `AddK`\n", |
446 | 316 | "Takes |x> to |x + k> for a classical integer `k`.\n", |
447 | 317 | "\n", |
448 | | - "Applies addition to input register `|x>` given classical integer 'k'.\n", |
449 | | - "\n", |
450 | | - "This is the simple version of constant addition because it involves simply converting the\n", |
451 | | - "classical integer into a quantum parameter and using quantum-quantum addition as opposed to\n", |
452 | | - "designing a bespoke circuit for constant addition based on the classical parameter.\n", |
| 318 | + "This construction simply XORs the classical constant into a quantum register and\n", |
| 319 | + "applies quantum-quantum addition. This is the lowest T-count algorithm at the expense\n", |
| 320 | + "of $n$ auxiliary qubits. This construction also permits an inexpensive controlled version:\n", |
| 321 | + "you only need to control the loading of the classical constant which can be done with\n", |
| 322 | + "only clifford operations.\n", |
453 | 323 | "\n", |
454 | 324 | "#### Parameters\n", |
455 | 325 | " - `bitsize`: Number of bits used to represent each integer.\n", |
|
461 | 331 | " - `x`: A bitsize-sized input register (register x above). \n", |
462 | 332 | "\n", |
463 | 333 | "#### References\n", |
464 | | - " - [Improved quantum circuits for elliptic curve discrete logarithms](https://arxiv.org/abs/2001.09580). Fig 2a\n" |
| 334 | + " - [Improved quantum circuits for elliptic curve discrete logarithms](https://arxiv.org/abs/2001.09580). Haner et. al. 2020. Section 3: Components. \"Integer addition\" and Fig 2a.\n" |
465 | 335 | ] |
466 | 336 | }, |
467 | 337 | { |
468 | 338 | "cell_type": "code", |
469 | 339 | "execution_count": null, |
470 | 340 | "id": "cd255bf9", |
471 | 341 | "metadata": { |
472 | | - "cq.autogen": "SimpleAddConstant.bloq_doc.py" |
| 342 | + "cq.autogen": "AddK.bloq_doc.py" |
473 | 343 | }, |
474 | 344 | "outputs": [], |
475 | 345 | "source": [ |
476 | | - "from qualtran.bloqs.arithmetic import SimpleAddConstant" |
| 346 | + "from qualtran.bloqs.arithmetic import AddK" |
477 | 347 | ] |
478 | 348 | }, |
479 | 349 | { |
480 | 350 | "cell_type": "markdown", |
481 | 351 | "id": "7538f9a5", |
482 | 352 | "metadata": { |
483 | | - "cq.autogen": "SimpleAddConstant.example_instances.md" |
| 353 | + "cq.autogen": "AddK.example_instances.md" |
484 | 354 | }, |
485 | 355 | "source": [ |
486 | 356 | "### Example Instances" |
|
491 | 361 | "execution_count": null, |
492 | 362 | "id": "4305289f", |
493 | 363 | "metadata": { |
494 | | - "cq.autogen": "SimpleAddConstant.simple_add_k_symb" |
| 364 | + "cq.autogen": "AddK.add_k" |
495 | 365 | }, |
496 | 366 | "outputs": [], |
497 | 367 | "source": [ |
498 | 368 | "n, k = sympy.symbols('n k')\n", |
499 | | - "simple_add_k_symb = SimpleAddConstant(bitsize=n, k=k)" |
| 369 | + "add_k = AddK(bitsize=n, k=k)" |
500 | 370 | ] |
501 | 371 | }, |
502 | 372 | { |
503 | 373 | "cell_type": "code", |
504 | 374 | "execution_count": null, |
505 | 375 | "id": "f6048819", |
506 | 376 | "metadata": { |
507 | | - "cq.autogen": "SimpleAddConstant.simple_add_k_small" |
| 377 | + "cq.autogen": "AddK.add_k_small" |
508 | 378 | }, |
509 | 379 | "outputs": [], |
510 | 380 | "source": [ |
511 | | - "simple_add_k_small = SimpleAddConstant(bitsize=4, k=2, signed=False)" |
| 381 | + "add_k_small = AddK(bitsize=4, k=2, signed=False)" |
512 | 382 | ] |
513 | 383 | }, |
514 | 384 | { |
515 | 385 | "cell_type": "code", |
516 | 386 | "execution_count": null, |
517 | 387 | "id": "b67fd469", |
518 | 388 | "metadata": { |
519 | | - "cq.autogen": "SimpleAddConstant.simple_add_k_large" |
| 389 | + "cq.autogen": "AddK.add_k_large" |
520 | 390 | }, |
521 | 391 | "outputs": [], |
522 | 392 | "source": [ |
523 | | - "simple_add_k_large = SimpleAddConstant(bitsize=64, k=-23, signed=True)" |
| 393 | + "add_k_large = AddK(bitsize=64, k=-23, signed=True)" |
524 | 394 | ] |
525 | 395 | }, |
526 | 396 | { |
527 | 397 | "cell_type": "markdown", |
528 | 398 | "id": "b8b04228", |
529 | 399 | "metadata": { |
530 | | - "cq.autogen": "SimpleAddConstant.graphical_signature.md" |
| 400 | + "cq.autogen": "AddK.graphical_signature.md" |
531 | 401 | }, |
532 | 402 | "source": [ |
533 | 403 | "#### Graphical Signature" |
|
538 | 408 | "execution_count": null, |
539 | 409 | "id": "e93e7f2e", |
540 | 410 | "metadata": { |
541 | | - "cq.autogen": "SimpleAddConstant.graphical_signature.py" |
| 411 | + "cq.autogen": "AddK.graphical_signature.py" |
542 | 412 | }, |
543 | 413 | "outputs": [], |
544 | 414 | "source": [ |
545 | 415 | "from qualtran.drawing import show_bloqs\n", |
546 | | - "show_bloqs([simple_add_k_small, simple_add_k_large],\n", |
547 | | - " ['`simple_add_k_small`', '`simple_add_k_large`'])" |
| 416 | + "show_bloqs([add_k, add_k_small, add_k_large],\n", |
| 417 | + " ['`add_k`', '`add_k_small`', '`add_k_large`'])" |
548 | 418 | ] |
549 | 419 | }, |
550 | 420 | { |
551 | 421 | "cell_type": "markdown", |
552 | 422 | "id": "13552795", |
553 | 423 | "metadata": { |
554 | | - "cq.autogen": "SimpleAddConstant.call_graph.md" |
| 424 | + "cq.autogen": "AddK.call_graph.md" |
555 | 425 | }, |
556 | 426 | "source": [ |
557 | 427 | "### Call Graph" |
|
562 | 432 | "execution_count": null, |
563 | 433 | "id": "d8d6584e", |
564 | 434 | "metadata": { |
565 | | - "cq.autogen": "SimpleAddConstant.call_graph.py" |
| 435 | + "cq.autogen": "AddK.call_graph.py" |
566 | 436 | }, |
567 | 437 | "outputs": [], |
568 | 438 | "source": [ |
569 | 439 | "from qualtran.resource_counting.generalizers import ignore_split_join\n", |
570 | | - "simple_add_k_small_g, simple_add_k_small_sigma = simple_add_k_small.call_graph(max_depth=1, generalizer=ignore_split_join)\n", |
571 | | - "show_call_graph(simple_add_k_small_g)\n", |
572 | | - "show_counts_sigma(simple_add_k_small_sigma)" |
| 440 | + "add_k_g, add_k_sigma = add_k.call_graph(max_depth=1, generalizer=ignore_split_join)\n", |
| 441 | + "show_call_graph(add_k_g)\n", |
| 442 | + "show_counts_sigma(add_k_sigma)" |
573 | 443 | ] |
574 | 444 | }, |
575 | 445 | { |
|
0 commit comments