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