mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 07:57:19 -05:00
Create comprehensive research-lab pack structure with mathematical and quantum computing modules from blackroad-prism-console: Math Modules: - hilbert_core.py: Hilbert space symbolic reasoning - collatz/: Distributed Collatz conjecture verification - linmath/: Linear mathematics C library - lucidia_math_forge/: Symbolic proof engine - lucidia_math_lab/: Experimental mathematics Quantum Modules: - lucidia_quantum/: Quantum core - quantum_engine/: Circuit simulation Experiments: - br_math/: Gödel gap, quantum experiments Includes pack.yaml manifest and comprehensive README. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Backend interfaces for Quantum ML.
|
|
|
|
Currently only the local Aer CPU simulator is implemented. GPU support is
|
|
stubbed out and disabled unless ``LUCIDIA_QML_GPU`` is set.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
from qiskit import QuantumCircuit
|
|
|
|
|
|
class QuantumBackend(ABC):
|
|
"""Abstract quantum backend."""
|
|
|
|
@abstractmethod
|
|
def run(self, circuit: QuantumCircuit, shots: int = 1024, seed: int | None = None) -> Any:
|
|
"""Execute a circuit and return the raw result."""
|
|
|
|
|
|
class AerCPUBackend(QuantumBackend):
|
|
"""Qiskit Aer CPU simulator backend."""
|
|
|
|
def __init__(self) -> None:
|
|
from qiskit_aer import AerSimulator
|
|
|
|
self.simulator = AerSimulator(method="automatic")
|
|
|
|
def run(self, circuit: QuantumCircuit, shots: int = 1024, seed: int | None = None) -> Any:
|
|
if seed is not None:
|
|
circuit = circuit.copy()
|
|
circuit.seed_simulator(seed)
|
|
job = self.simulator.run(circuit, shots=shots)
|
|
return job.result()
|
|
|
|
|
|
class AerGPUBackend(AerCPUBackend):
|
|
"""Stub GPU backend. Requires CUDA and qiskit-aer-gpu."""
|
|
|
|
def __init__(self) -> None:
|
|
if os.getenv("LUCIDIA_QML_GPU", "off").lower() not in {"1", "true", "on"}:
|
|
raise RuntimeError("GPU backend disabled")
|
|
super().__init__()
|
|
try:
|
|
self.simulator.set_options(device="GPU") # type: ignore[attr-defined]
|
|
except Exception as exc: # pragma: no cover - fallback path
|
|
raise RuntimeError("GPU backend not available") from exc
|