microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/npm/qsharp/ux/circuit-vis/gateRenderData.ts
73lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT license. |
| 3 | |
| 4 | import { DataAttributes } from "./circuit.js"; |
| 5 | import { Register } from "./register.js"; |
| 6 | |
| 7 | /** |
| 8 | * Enum for the various gate operations handled. |
| 9 | */ |
| 10 | export enum GateType { |
| 11 | /** Measurement gate. */ |
| 12 | Measure, |
| 13 | /** CNOT gate. */ |
| 14 | Cnot, |
| 15 | /** SWAP gate. */ |
| 16 | Swap, |
| 17 | /** X gate. */ |
| 18 | X, |
| 19 | /** |0⟩or |1⟩ gate. */ |
| 20 | Ket, |
| 21 | /** Single/multi qubit unitary gate. */ |
| 22 | Unitary, |
| 23 | /** Single/multi controlled unitary gate. */ |
| 24 | ControlledUnitary, |
| 25 | /** Group of nested gates */ |
| 26 | Group, |
| 27 | /** Invalid gate. */ |
| 28 | Invalid, |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Rendering data used to store information pertaining to a given |
| 33 | * operation for rendering its corresponding SVG. |
| 34 | */ |
| 35 | export interface GateRenderData { |
| 36 | /** Gate type. */ |
| 37 | type: GateType; |
| 38 | /** Whether this group gate is currently expanded. Always false for non-group gates. */ |
| 39 | isExpanded: boolean; |
| 40 | /** Centre x coord for gate position. */ |
| 41 | x: number; |
| 42 | /** Array of y coords of control registers. */ |
| 43 | controlsY: number[]; |
| 44 | /** Array of y coords of target registers. |
| 45 | * For `GateType.Unitary` or `GateType.ControlledUnitary`, this is an array of groups of |
| 46 | * y coords, where each group represents a unitary box to be rendered separately. |
| 47 | */ |
| 48 | targetsY: (number | number[])[]; |
| 49 | /** Gate label. */ |
| 50 | label: string; |
| 51 | /** Gate arguments as string. */ |
| 52 | displayArgs?: string; |
| 53 | /** Gate width. */ |
| 54 | width: number; |
| 55 | /** Children operations as part of group. */ |
| 56 | children?: GateRenderData[][]; |
| 57 | /** Vertical space from the top of this gate to the top of the topmost contained gate. 0 for non-groups. */ |
| 58 | topPadding: number; |
| 59 | /** Vertical space from the bottom of this gate to the bottom of the bottommost contained gate. 0 for non-groups. */ |
| 60 | bottomPadding: number; |
| 61 | /** Custom data attributes to attach to gate element. */ |
| 62 | dataAttributes?: DataAttributes; |
| 63 | /** Link href and title for clickable gate. */ |
| 64 | link?: { href: string; title: string }; |
| 65 | /** Labels for the classical control registers (when present, this group is rendered with classical controls). */ |
| 66 | classicalControlIds?: (number | null)[]; |
| 67 | /** |
| 68 | * Classical control registers used by this operation or any descendant. |
| 69 | * Used by processOperations to decide which classical wires may pass through |
| 70 | * this gate body without forcing a split. |
| 71 | */ |
| 72 | classicalControlRegs?: Register[]; |
| 73 | } |