-
Notifications
You must be signed in to change notification settings - Fork 0
Quantum Computing Emulation
Sofia Engine provides a mathematically sound, high-precision Quantum Computing Emulator (sofia_ai.quantum) that simulates pure complex statevectors in Hilbert space
A pure quantum state
Sofia's QuantumCircuit implements full unitary transformations:
-
Hadamard (
$H$ ): Creates equal quantum superposition: $$H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \ 1 & -1 \end{bmatrix}$$ -
Pauli Gates (
$X, Y, Z$ ): $$X = \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix}, \quad Y = \begin{bmatrix} 0 & -j \ j & 0 \end{bmatrix}, \quad Z = \begin{bmatrix} 1 & 0 \ 0 & -1 \end{bmatrix}$$ -
Phase & T Gates (
$S, T$ ): $$S = \begin{bmatrix} 1 & 0 \ 0 & j \end{bmatrix}, \quad T = \begin{bmatrix} 1 & 0 \ 0 & e^{j \pi/4} \end{bmatrix}$$ -
Parametric Rotations (
$R_x, R_y, R_z$ ): $$R_y(\theta) = \begin{bmatrix} \cos(\theta/2) & -\sin(\theta/2) \ \sin(\theta/2) & \cos(\theta/2) \end{bmatrix}$$ -
Entangling Gates (CNOT /
$CX$ , Controlled-Z /$CZ$ ): $$CX = \begin{bmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 1 \ 0 & 0 & 1 & 0 \end{bmatrix}$$
Encodes real-valued sensor features
For quantum support vector machines and non-linear anomaly detection, Sofia evaluates quantum state transition fidelity:
Where
from sofia_ai.quantum import QuantumCircuit, QuantumKernel
# 1. Simulate Bell State Entanglement
qc = QuantumCircuit(num_qubits=2)
qc.h(0).cx(0, 1)
# Measurement sampling (1024 shots)
shots = qc.measure(shots=1024)
print("Measurement counts:", shots) # {'00': ~512, '11': ~512}
# 2. Quantum Kernel Anomaly Scoring
kernel = QuantumKernel(num_qubits=4)
normal_baseline = [0.1, 0.2, 0.15, 0.18]
test_sample = [0.12, 0.22, 0.14, 0.19]
similarity = kernel.evaluate(normal_baseline, test_sample)
print(f"Quantum Kernel Similarity: {similarity:.4f}")import { QuantumCircuit, QuantumKernel } from "@rootcastle/sofia-engine";
const qc = new QuantumCircuit(2);
qc.h(0).cx(0, 1);
const counts = qc.measure(1000);
console.log("Shots:", counts);
const kernel = new QuantumKernel(3);
const sim = kernel.evaluate([0.1, 0.5, 0.9], [0.1, 0.5, 0.9]);
console.log("Fidelity:", sim); // 1.0000