Lowering
Squin
dataclass
Squin(circuit: Circuit)
Bases: LoweringABC[Circuit]
flowchart TD
bloqade.cirq_utils.lowering.Squin[Squin]
click bloqade.cirq_utils.lowering.Squin href "" "bloqade.cirq_utils.lowering.Squin"
Lower a cirq.Circuit object to a squin kernel
__post_init__
__post_init__()
Map Cirq qubits to allocation-order register indices.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
212 213 214 215 216 | |
allocate_register
allocate_register(state: State[Circuit]) -> ir.SSAValue
Allocate circuit qubits in the lowerer's selected order.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
233 234 235 236 | |
generic_visit
generic_visit(state: State[Circuit], node: CirqNode)
Reject Cirq nodes without a supported lowering method.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
288 289 290 291 292 293 294 | |
lower_global
lower_global(
state: State[Circuit], node: CirqNode
) -> lowering.LoweringABC.Result
Reject global values in Cirq circuits.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
300 301 302 303 304 | |
lower_literal
lower_literal(state: State[Circuit], value) -> ir.SSAValue
Reject standalone literals in Cirq circuits.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
296 297 298 | |
lower_qubit_getindex
lower_qubit_getindex(state: State[Circuit], qid: Qid)
Look up one Cirq qubit in the SQuIN register.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
218 219 220 221 222 223 | |
lower_qubit_getindices
lower_qubit_getindices(
state: State[Circuit], qids: tuple[Qid, ...]
)
Collect register entries for a tuple of Cirq qubits.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
225 226 227 228 229 230 231 | |
run
run(
stmt: Circuit,
*,
source: str | None = None,
globals: dict[str, Any] | None = None,
file: str | None = None,
lineno_offset: int = 0,
col_offset: int = 0,
compactify: bool = True,
register_as_argument: bool = False,
register_argument_name: str = "q"
) -> ir.Region
Lower a Cirq circuit into a Kirin region.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
visit
visit(
state: State[Circuit], node: CirqNode
) -> lowering.Result
Dispatch a Cirq node to its lowering method.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
281 282 283 284 285 286 | |
visit_AsymmetricDepolarizingChannel
visit_AsymmetricDepolarizingChannel(
state: State[Circuit],
node: AsymmetricDepolarizingChannel,
)
Lower one- or two-qubit asymmetric Pauli noise.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
visit_BitFlipChannel
visit_BitFlipChannel(
state: State[Circuit], node: BitFlipChannel
)
Lower bit-flip noise to a single-qubit Pauli channel.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
677 678 679 680 681 682 683 684 685 686 687 | |
visit_CCZPowGate
visit_CCZPowGate(
state: State[Circuit], node: GateOperation
)
Lower a cirq CCZ power gate with an odd integer exponent to a CCZ gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
visit_CXPowGate
visit_CXPowGate(state: State[Circuit], node: GateOperation)
Lower an odd CX power, rejecting unsupported exponents.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
visit_CZPowGate
visit_CZPowGate(state: State[Circuit], node: GateOperation)
Lower an odd CZ power, rejecting unsupported exponents.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
visit_Circuit
visit_Circuit(
state: State[Circuit], node: Circuit | FrozenCircuit
) -> lowering.Result
Lower the moments of a circuit in order.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
306 307 308 309 310 311 312 313 | |
visit_CircuitOperation
visit_CircuitOperation(
state: State[Circuit], node: CircuitOperation
)
Lower a circuit operation with a supported repetition count.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
visit_ClassicallyControlledOperation
visit_ClassicallyControlledOperation(
state: State[Circuit],
node: ClassicallyControlledOperation,
)
Lower a classically controlled operation to conditional IR.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
visit_ControlledOperation
visit_ControlledOperation(
state: State[Circuit], node: ControlledOperation
)
Lower a supported controlled Pauli operation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
visit_DepolarizingChannel
visit_DepolarizingChannel(
state: State[Circuit], node: DepolarizingChannel
)
Lower a depolarizing channel to SQuIN noise IR.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
689 690 691 692 693 694 695 | |
visit_FrozenCircuit
visit_FrozenCircuit(
state: State[Circuit], node: FrozenCircuit
)
Lower a frozen circuit using the ordinary circuit visitor.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
653 654 655 656 657 | |
visit_GateOperation
visit_GateOperation(
state: State[Circuit], node: GateOperation
)
Decompose selected gates or dispatch by gate type.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
visit_HPowGate
visit_HPowGate(state: State[Circuit], node: HPowGate)
Lower a Hadamard power, decomposing non-Hadamard exponents.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
454 455 456 457 458 459 460 461 462 463 | |
visit_MeasurementGate
visit_MeasurementGate(
state: State[Circuit], node: GateOperation
) -> ir.Statement
Lower a Cirq measurement and bind its result key.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
visit_Moment
visit_Moment(
state: State[Circuit], node: Moment
) -> lowering.Result
Lower each operation in a Cirq moment.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
315 316 317 318 319 320 | |
visit_PhasedXZGate
visit_PhasedXZGate(
state: State[Circuit], node: GateOperation
)
Lower a phased-XZ gate with converted exponent units.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
525 526 527 528 529 530 531 532 533 534 535 536 537 | |
visit_ResetChannel
visit_ResetChannel(
state: State[Circuit], node: ResetChannel
)
Lower a Cirq reset channel to a SQuIN reset.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
747 748 749 750 751 752 753 | |
visit_Rx
visit_Rx(state: State[Circuit], node: GateOperation)
Lower a Cirq X rotation to a SQuIN X rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
507 508 509 510 511 | |
visit_Ry
visit_Ry(state: State[Circuit], node: GateOperation)
Lower a Cirq Y rotation to a SQuIN Y rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
513 514 515 516 517 | |
visit_Rz
visit_Rz(state: State[Circuit], node: GateOperation)
Lower a Cirq Z rotation to a SQuIN Z rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
519 520 521 522 523 | |
visit_SingleQubitPauliStringGateOperation
visit_SingleQubitPauliStringGateOperation(
state: State[Circuit],
node: SingleQubitPauliStringGateOperation,
)
Lower a single-qubit Pauli-string operation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
visit_SwapPowGate
visit_SwapPowGate(
state: State[Circuit], node: GateOperation
)
Lower an odd SWAP power, rejecting unsupported exponents.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
visit_TaggedOperation
visit_TaggedOperation(
state: State[Circuit], node: TaggedOperation
)
Lower a tagged operation without its tags.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
337 338 339 340 341 | |
visit_XPowGate
visit_XPowGate(state: State[Circuit], node: GateOperation)
Lower an X power as X or an X rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
465 466 467 468 469 470 471 472 473 474 | |
visit_YPowGate
visit_YPowGate(state: State[Circuit], node: GateOperation)
Lower a Y power as Y or a Y rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
476 477 478 479 480 481 482 483 484 485 | |
visit_ZPowGate
visit_ZPowGate(state: State[Circuit], node: GateOperation)
Lower a Z power as S, T, Z, or a Z rotation.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
visit_ZZPowGate
visit_ZZPowGate(state: State[Circuit], node: GateOperation)
Lower a ZZ power directly or through a CX-Rz-CX sequence.
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
load_circuit
load_circuit(
circuit: Circuit,
kernel_name: str = "main",
dialects: DialectGroup = kernel,
register_as_argument: bool = False,
return_register: bool = False,
register_argument_name: str = "q",
globals: dict[str, Any] | None = None,
file: str | None = None,
lineno_offset: int = 0,
col_offset: int = 0,
compactify: bool = True,
)
Convert a Cirq circuit into a kernel for the supplied dialect group.
A registered dialect-specific lowerer is selected when exactly one dialect in the group has one; otherwise the SQuIN lowerer is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The circuit to load. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
kernel_name |
str
|
The name of the kernel to load. Defaults to "main". |
dialects |
DialectGroup
|
Dialects and pass pipeline for the result.
Defaults to |
register_as_argument |
bool
|
Determine whether the resulting kernel function should accept
a single |
return_register |
bool
|
Determine whether the resulting kernel functionr returns a
single value of type |
register_argument_name |
str
|
The name of the argument that represents the qubit register.
Only used when |
globals |
dict[str, Any] | None
|
The global variables to use. Defaults to None. |
file |
str | None
|
The file name for error reporting. Defaults to None. |
lineno_offset |
int
|
The line number offset for error reporting. Defaults to 0. |
col_offset |
int
|
The column number offset for error reporting. Defaults to 0. |
compactify |
bool
|
Whether to compactify the output. Defaults to True. |
Usage Examples:
# from cirq's "hello qubit" example
import cirq
from bloqade.cirq_utils import load_circuit
# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
# Create a circuit.
circuit = cirq.Circuit(
cirq.X(qubit)**0.5, # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
)
# load the circuit as squin
main = load_circuit(circuit)
# print the resulting IR
main.print()
You can also compose kernel functions generated from circuits by passing in and / or returning the respective quantum registers:
import cirq
from bloqade.cirq_utils import load_circuit
from bloqade import squin
q = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q[0]), cirq.CX(*q))
get_entangled_qubits = load_circuit(
circuit, return_register=True, kernel_name="get_entangled_qubits"
)
get_entangled_qubits.print()
entangle_qubits = load_circuit(
circuit, register_as_argument=True, kernel_name="entangle_qubits"
)
@squin.kernel
def main():
qreg = get_entangled_qubits()
qreg2 = squin.qalloc(1)
entangle_qubits([qreg[1], qreg2[0]])
return squin.qubit.measure(qreg2)
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |