Skip to the content.

Topological Quantum Computing - Architecture Guide

Overview

The FSharp.Azure.Quantum.Topological library follows a strictly layered architecture that separates concerns and enables composition. This architecture mirrors the gate-based quantum computing library, implementing a fundamentally different paradigm while integrating with it via the shared IQuantumBackend interface.

Architectural Layers

┌─────────────────────────────────────────────────────────┐
│  Layer 6: Builders, Formats & Utilities                 │
│  User-friendly DSL, file formats, helpers               │
│  Files: TopologicalBuilder.fs, TopologicalFormat.fs,    │
│         Visualization.fs, NoiseModels.fs,               │
│         DeviceProfile.fs, TopologicalHelpers.fs,        │
│         TopologicalError.fs                             │
└─────────────────────────────────────────────────────────┘
                           ▼
┌─────────────────────────────────────────────────────────┐
│  Layer 5: Compilation & Integration                     │
│  Gate-to-braid conversion, optimization, algorithm ext. │
│  Files: GateToBraid.fs, BraidToGate.fs,                 │
│         SolovayKitaev.fs, CircuitOptimization.fs,       │
│         AlgorithmExtensions.fs                          │
└─────────────────────────────────────────────────────────┘
                           ▼
┌─────────────────────────────────────────────────────────┐
│  Layer 4: Algorithms                                     │
│  Topological-specific algorithms & error correction     │
│  Files: MagicStateDistillation.fs, ToricCode.fs,        │
│         SurfaceCode.fs, AnyonicErrorCorrection.fs,      │
│         ErrorPropagation.fs                             │
└─────────────────────────────────────────────────────────┘
                           ▼
┌─────────────────────────────────────────────────────────┐
│  Layer 3: Operations (High-Level)                       │
│  Qubit encoding, braiding sequences, measurement        │
│  Files: TopologicalOperations.fs, FusionTree.fs         │
└─────────────────────────────────────────────────────────┘
                           ▼
┌─────────────────────────────────────────────────────────┐
│  Layer 2: Backends (Execution)                          │
│  Unified IQuantumBackend                                │
│  Files: TopologicalBackend.fs                           │
└─────────────────────────────────────────────────────────┘
                           ▼
┌─────────────────────────────────────────────────────────┐
│  Layer 1: Core (Mathematical Foundation)                │
│  Pure functions: anyon species, fusion, braiding, knots │
│  Files: AnyonSpecies.fs, FusionRules.fs,                │
│         BraidingOperators.fs, FMatrix.fs, RMatrix.fs,   │
│         ModularData.fs, BraidGroup.fs,                  │
│         BraidingConsistency.fs, EntanglementEntropy.fs, │
│         KauffmanBracket.fs, KnotConstructors.fs         │
└─────────────────────────────────────────────────────────┘

Layer Descriptions

Layer 1: Core - Mathematical Foundation

Purpose: Pure mathematical primitives with no side effects or I/O.

Key Modules:

Design Principles:

Example:

open FSharp.Azure.Quantum.Topological

// Pure function - no side effects
let sigma = AnyonSpecies.Particle.Sigma
let channels = FusionRules.channels sigma sigma AnyonSpecies.AnyonType.Ising
// Result: Ok [Vacuum; Psi] (deterministic, no I/O)

Layer 2: Backends - Execution Abstraction

Purpose: Abstract execution of topological quantum operations across different backends (simulator, hardware).

Key Interfaces:

Implementations:

Design Principles:

Example:

open FSharp.Azure.Quantum.Core.BackendAbstraction

// Unified backend (recommended); the argument caps the number of anyons
let backend = TopologicalUnifiedBackendFactory.createIsing 10

// InitializeState takes logical qubits: 2 qubits = 6 Ising anyons
match backend.InitializeState 2 with
| Ok state -> printfn "Native state type: %A" backend.NativeStateType
| Error err -> printfn "Error: %s" err.Message

Layer 3: Operations - High-Level Quantum Operations

Purpose: Build meaningful quantum operations on fusion-tree states. The backend (Layer 2) delegates to these functions.

Key Modules:

Design Principles:

Example:

// High-level operation composed from Layer 3 primitives
let applyGate (state: TopologicalOperations.Superposition) =
    TopologicalOperations.braidSuperposition 0 state
    |> Result.bind (TopologicalOperations.braidSuperposition 2)

Layer 4: Algorithms - Domain-Specific Algorithms

Purpose: Implement algorithms specific to topological quantum computing.

Implemented:

Note: Standard quantum algorithms (Grover, QFT, Shor, HHL) run on topological backends via AlgorithmExtensions (Layer 5), not as topological-native algorithms.

Design Principles:

Example:

// Topological-specific computation: knot invariants from a planar diagram
let trefoil = KnotConstructors.trefoil true
let bracket = KauffmanBracket.Planar.evaluateBracketStateSum trefoil KauffmanBracket.Planar.standardA
let jones = KauffmanBracket.Planar.jonesPolynomial trefoil KauffmanBracket.Planar.standardA

// Resource model for magic state distillation (p_out ≈ 35 p³ per round)
let estimate = MagicStateDistillation.estimateResources 0.9999 0.95

Layer 5: Compilation & Integration

Purpose: Convert between gate-based and topological representations, optimize circuits, and enable standard algorithms on topological backends.

Key Modules:

Design Principles:

Example:

open FSharp.Azure.Quantum.Algorithms
open FSharp.Azure.Quantum.GroverSearch

// Standard algorithms work on topological backends (8 qubits = 18 Ising anyons)
let backend20 = TopologicalUnifiedBackendFactory.createIsing 20
let result = AlgorithmExtensions.searchSingleWithTopology 42 8 backend20 Grover.defaultConfig
let qft = AlgorithmExtensions.qftWithTopology 4 backend20 QFT.defaultConfig

Running on the topological simulator models braiding; it is not faster than the gate-based simulator.

Layer 6: Builders, Formats & Utilities

Purpose: Provide user-friendly DSL for composing quantum programs, file formats, and supporting utilities.

Key Modules:

Design Principles:

Example:

let program = topological backend {
    do! TopologicalBuilder.initialize AnyonSpecies.AnyonType.Ising 2
    do! TopologicalBuilder.braid 0
    do! TopologicalBuilder.braid 2
    let! outcome = TopologicalBuilder.measure 0
    return outcome
}

// Run it: Task<Result<AnyonSpecies.Particle, QuantumError>>
let outcomeTask = TopologicalBuilder.execute backend program

Relationship with Gate-Based Library

Different Paradigms, Shared Interface

Fundamental Differences:

Aspect Gate-Based Topological
Operations H, CNOT, Rz gates Braiding anyons
State Amplitude vectors Fusion trees
Qubits Direct 2-state Encoded in anyon pairs
Measurement Z-basis (0 or 1) Fusion outcomes (e.g. 1 or ψ for a σ pair)
Algorithms Shor’s, HHL, VQE Kauffman, topological codes

Integration via IQuantumBackend

While the paradigms differ, the topological backend implements IQuantumBackend from the gate-based library. This enables:

Shared Patterns (Same Structure, Different Content)

The gate-based library groups files in folders; the topological library keeps its files in one folder, ordered by layer in the .fsproj:

Gate-Based (folders):               Topological (layers):
├── LocalSimulator/                 ├── Layer 1: AnyonSpecies.fs,
│   ├── Gates.fs                    │            FusionRules.fs, ...
│   └── StateVector.fs              │
├── Core/                           ├── Layer 2: TopologicalBackend.fs
│   └── BackendAbstraction.fs       │   (implements IQuantumBackend - shared!)
│       (IQuantumBackend)           │
├── Backends/                       │
│   └── LocalBackend.fs             │
├── Algorithms/                     ├── Layer 4/5: MagicStateDistillation.fs,
│   ├── Shor.fs                     │              AlgorithmExtensions.fs
│   └── Grover.fs                   │
└── Builders/                       └── Layer 6: TopologicalBuilder.fs
    └── CircuitBuilder.fs

Design Principles

1. Idiomatic F#

✅ Immutability by default

// ✅ GOOD: Immutable state transformation - braiding returns a new superposition
let braidOnce (state: TopologicalOperations.Superposition) =
    TopologicalOperations.braidSuperposition 0 state

// ❌ BAD: a mutating method such as state.Braid(0) - the library has none

✅ Pattern matching over inheritance

// ✅ GOOD: Discriminated union (AnyonSpecies.Particle) and pattern matching
let describe (particle: AnyonSpecies.Particle) =
    match particle with
    | AnyonSpecies.Particle.Vacuum -> "vacuum"
    | AnyonSpecies.Particle.Sigma -> "Ising sigma"
    | AnyonSpecies.Particle.Psi -> "Ising fermion"
    | AnyonSpecies.Particle.Tau -> "Fibonacci tau"
    | AnyonSpecies.Particle.SpinJ(jDoubled, level) -> $"SU(2)_{level} spin {jDoubled}/2"

// ❌ BAD: a class hierarchy such as `type Sigma() = inherit Particle()`

✅ Functions over methods

// ✅ GOOD: Module with functions (FusionRules.channels a b theory)
let sigmaChannels =
    FusionRules.channels AnyonSpecies.Particle.Sigma AnyonSpecies.Particle.Sigma AnyonSpecies.AnyonType.Ising

// ❌ BAD: a static class method such as FusionRules.Channels(a, b, theory)

✅ Composition over configuration

// ✅ GOOD: Compose small functions (they return Result, so bind them)
let braidAt index = TopologicalOperations.braidSuperposition index
let braidWord = braidAt 0 >> Result.bind (braidAt 2) >> Result.bind (braidAt 0)

// ❌ BAD: a configuration object with Braid1/Braid2 properties

2. Type Safety

✅ Domain-driven types

// Not just strings! The library defines
//   AnyonSpecies.AnyonType = Ising | Fibonacci | SU2Level of level: int
//   AnyonSpecies.Particle  = Vacuum | Sigma | Psi | Tau | SpinJ of j_doubled: int * level: int
let theory = AnyonSpecies.AnyonType.SU2Level 3

✅ Option for optional values

// TopologicalOperations.OperationResult =
//   { State: FusionTree.State; Amplitude: Complex; ClassicalOutcome: AnyonSpecies.Particle option }
let outcomeName (result: TopologicalOperations.OperationResult) =
    match result.ClassicalOutcome with
    | Some particle -> string particle   // Not null!
    | None -> "no measurement"

✅ Result for errors

open FSharp.Azure.Quantum.Core.BackendAbstraction

let validateCapabilities (backend: IQuantumBackend) : Result<unit, string> =
    if backend.SupportsOperation(QuantumOperation.Braid 0) then Ok ()
    else Error "Backend lacks braiding support"

3. Testability

✅ Business-meaningful assertions

// In the test project this function carries xUnit's [<Fact>] attribute
let ``Two sigma anyons have two fusion channels (1 qubit)`` () =
    // Not just: Assert.Equal(2, dimension)
    // But: Clear business meaning!
    let sigma = AnyonSpecies.Particle.Sigma
    match FusionRules.channels sigma sigma AnyonSpecies.AnyonType.Ising with
    | Ok channels when List.length channels = 2 -> ()
    | other -> failwithf "Expected two fusion channels, got %A" other

✅ Pure functions are inherently testable

// No mocking needed - pure function!
let fused = FusionRules.channels AnyonSpecies.Particle.Sigma AnyonSpecies.Particle.Sigma AnyonSpecies.AnyonType.Ising
// fused = Ok [Vacuum; Psi]

4. Performance

✅ Count before you enumerate

let sigmas = List.replicate 6 AnyonSpecies.Particle.Sigma

// Counts the fusion space without building every tree
let dimension = FusionTree.fusionSpaceDimension sigmas AnyonSpecies.Particle.Vacuum AnyonSpecies.AnyonType.Ising

// Builds every tree - only when you need them
let allTrees = FusionTree.allTrees sigmas AnyonSpecies.Particle.Vacuum AnyonSpecies.AnyonType.Ising

✅ Folds (or tail recursion) for long sequences

let braidSequence (indices: int list) (state: TopologicalOperations.Superposition) =
    indices
    |> List.fold (fun acc index -> acc |> Result.bind (TopologicalOperations.braidSuperposition index)) (Ok state)

Future Extensions

Planned Layers

  1. Hardware Adapters (Layer 2 Extensions)
    • Microsoft Majorana Gen 1 backend
    • Other topological hardware experiments
  2. Performance Optimizations
    • GPU acceleration
    • Sparse matrices
    • Parallel braiding

Integration Points

Current Bridges:

Potential Future Bridges:

References

Contributing

When adding new features, always:

  1. ✅ Place in correct layer (see diagram above)
  2. ✅ Follow idiomatic F# principles
  3. ✅ Write business-meaningful tests
  4. ✅ Update this architecture document
  5. ✅ Keep topological-specific code in this package (shared interfaces live in the gate-based library)

Remember: We’re building a companion library that follows the same architectural pattern as the gate-based library, sharing the IQuantumBackend interface for interoperability!