forked from Thorium/FSharp.Azure.Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopologicalVisualization.fsx
More file actions
153 lines (122 loc) · 5.44 KB
/
Copy pathTopologicalVisualization.fsx
File metadata and controls
153 lines (122 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
// Topological Quantum Computing Visualization Example
// Demonstrates visualization of fusion trees and quantum superpositions
// Reference local build (use this for development/testing)
#r "../../src/FSharp.Azure.Quantum/bin/Debug/net10.0/FSharp.Azure.Quantum.dll"
#r "../../src/FSharp.Azure.Quantum.Topological/bin/Debug/net10.0/FSharp.Azure.Quantum.Topological.dll"
// Or use published NuGet package (uncomment when package is published):
// #r "nuget: FSharp.Azure.Quantum"
// #r "nuget: FSharp.Azure.Quantum.Topological"
open FSharp.Azure.Quantum.Topological
open System.Numerics
printfn "=== TOPOLOGICAL QUANTUM COMPUTING VISUALIZATION ==="
printfn ""
// ============================================================================
// EXAMPLE 1: Fusion Tree Visualization (Topological Qubit)
// ============================================================================
printfn "EXAMPLE 1: Topological Qubit Encoding"
printfn "======================================"
printfn ""
// A topological qubit is encoded in the fusion outcome of 2 sigma anyons:
// |0⟩ ≡ σ × σ → 1 (vacuum)
// |1⟩ ≡ σ × σ → ψ (fermion)
let sigma = FusionTree.leaf AnyonSpecies.Particle.Sigma
// Computational basis state |0⟩
let qubitZero =
FusionTree.fuse sigma sigma AnyonSpecies.Particle.Vacuum
|> fun tree -> FusionTree.create tree AnyonSpecies.AnyonType.Ising
printfn "Qubit |0⟩:"
printfn "%s" (qubitZero.ToASCII())
printfn ""
printfn "Mermaid diagram:"
printfn "%s" (qubitZero.ToMermaid())
printfn ""
// Computational basis state |1⟩
let qubitOne =
FusionTree.fuse sigma sigma AnyonSpecies.Particle.Psi
|> fun tree -> FusionTree.create tree AnyonSpecies.AnyonType.Ising
printfn "Qubit |1⟩:"
printfn "%s" (qubitOne.ToASCII())
printfn ""
// ============================================================================
// EXAMPLE 2: Complex Fusion Tree (4 Anyons)
// ============================================================================
printfn "EXAMPLE 2: Four Sigma Anyons Fusion Tree"
printfn "=========================================="
printfn ""
// Create: ((σ × σ → 1) × (σ × σ → 1)) → 1
let leftPair = FusionTree.fuse sigma sigma AnyonSpecies.Particle.Vacuum
let rightPair = FusionTree.fuse sigma sigma AnyonSpecies.Particle.Vacuum
let fourSigmaTree =
FusionTree.fuse leftPair rightPair AnyonSpecies.Particle.Vacuum
|> fun tree -> FusionTree.create tree AnyonSpecies.AnyonType.Ising
printfn "%s" (fourSigmaTree.ToASCII())
printfn ""
printfn "Mermaid diagram:"
printfn "%s" (fourSigmaTree.ToMermaid())
printfn ""
// ============================================================================
// EXAMPLE 3: Quantum Superposition Visualization
// ============================================================================
printfn "EXAMPLE 3: Quantum Superposition State"
printfn "======================================="
printfn ""
// Create a uniform superposition of |0⟩ and |1⟩: (|0⟩ + |1⟩)/√2
let bellState = TopologicalOperations.uniform [qubitZero; qubitOne] AnyonSpecies.AnyonType.Ising
printfn "Bell State Superposition Terms:"
for (amp, state) in bellState.Terms do
printfn "Amplitude: %A" amp
printfn "%s" (state.ToASCII())
printfn ""
printfn "Mermaid diagrams for terms:"
for (amp, state) in bellState.Terms do
printfn "Amplitude: %A" amp
printfn "%s" (state.ToMermaid())
printfn ""
// ============================================================================
// EXAMPLE 4: Fibonacci Anyons
// ============================================================================
printfn "EXAMPLE 4: Fibonacci Anyon Fusion Tree"
printfn "======================================="
printfn ""
// Fibonacci anyons: τ × τ = 1 + τ (Fibonacci recurrence!)
let tau = FusionTree.leaf AnyonSpecies.Particle.Tau
// Create τ × τ → τ
let fibTree =
FusionTree.fuse tau tau AnyonSpecies.Particle.Tau
|> fun tree -> FusionTree.create tree AnyonSpecies.AnyonType.Fibonacci
printfn "%s" (fibTree.ToASCII())
printfn ""
printfn "Mermaid diagram:"
printfn "%s" (fibTree.ToMermaid())
printfn ""
// ============================================================================
// EXAMPLE 5: Superposition After Braiding
// ============================================================================
printfn "EXAMPLE 5: Superposition After Braiding Operation"
printfn "=================================================="
printfn ""
// Start with pure |0⟩ state
let initialState = TopologicalOperations.pureState qubitZero
// Apply braiding operation (braid anyons at positions 0 and 1)
match TopologicalOperations.braidSuperposition 0 initialState with
| Ok braidedState ->
printfn "After braiding anyon 0 and 1:"
for (amp, state) in braidedState.Terms do
printfn "Amplitude: %A" amp
printfn "%s" (state.ToASCII())
printfn ""
printfn "Mermaid diagram:"
for (amp, state) in braidedState.Terms do
printfn "Amplitude: %A" amp
printfn "%s" (state.ToMermaid())
| Error err ->
printfn "Error during braiding: %s" err.Message
printfn ""
printfn "=== VISUALIZATION EXAMPLES COMPLETE ==="
printfn ""
printfn "Key Insights:"
printfn "1. Fusion trees encode quantum states via anyon fusion outcomes"
printfn "2. Different fusion channels = orthogonal quantum states"
printfn "3. Superpositions combine multiple fusion tree basis states"
printfn "4. Braiding operations transform quantum amplitudes topologically"
printfn "5. Mermaid diagrams provide visual understanding of topological structures"