用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill quantum-computing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | quantum-computing |
| description | Quantum computing concepts and NeuralBlitz quantum neuron implementation |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"developers","category":"domain-specific"} |
When working with the NeuralBlitz quantum computing components or implementing quantum-inspired algorithms.
import numpy as np
from typing import Optional, Tuple
from scipy.linalg import expm
class QuantumState:
"""
Quantum state vector in Hilbert space.
The state is represented as a normalized complex vector.
For n qubits, the state space has dimension 2^n.
"""
def __init__(self, num_qubits: int) -> None:
"""
Initialize quantum state to |0⟩^n.
Args:
num_qubits: Number of qubits (must be positive integer)
"""
self.num_qubits = num_qubits
self.dim = 2 ** num_qubits
self.state = np.zeros(self.dim, dtype=complex)
self.state[0] = 1.0 # |0⟩ state
@property
def data(self) -> np.ndarray:
"""Return the state vector (read-only view)."""
return self.state.copy()
def normalize(self) -> None:
"""Normalize state vector to unit length."""
norm = np.linalg.norm(self.state)
if norm > 0:
self.state /= norm
def measure(self) -> int:
"""
Measure state in computational basis.
Returns:
Measured basis state index with probability = |<x|ψ⟩|²
"""
probs = np.abs(self.state) ** 2
probs /= probs.sum()
return np.random.choice(len(self.state), p=probabilities)
def fidelity(self, other: 'QuantumState') -> float:
"""
Calculate fidelity between two quantum states.
Fidelity = |⟨ψ|φ⟩|² for pure states.
Args:
other: Another quantum state to compare
Returns:
Fidelity value between 0 and 1
"""
overlap = np.vdot(self.state, other.state)
return np.abs(overlap) ** 2
class QuantumGate:
"""Quantum gate operations on state vectors."""
@staticmethod
def hadamard(num_qubits: int, target: int) -> np.ndarray:
"""
Create Hadamard gate for superposition.
H|0⟩ = (|0⟩ + |1⟩)/√2
H|1⟩ = (|0⟩ - |1⟩)/√2
"""
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
return QuantumGate.expand_gate(H, num_qubits, target)
@staticmethod
def pauli_x(num_qubits: int, target: int) -> np.ndarray:
"""Pauli-X (NOT) gate: |0⟩→|1⟩, |1⟩→|0⟩"""
X = np.array([[0, 1], [1, 0]])
return QuantumGate.expand_gate(X, num_qubits, target)
@staticmethod
def pauli_z(num_qubits: int, target: int) -> np.ndarray:
"""Pauli-Z gate: |1⟩→-|1⟩, |0⟩→|0⟩"""
Z = np.array([[1, 0], [0, -1]])
return QuantumGate.expand_gate(Z, num_qubits, target)
@staticmethod
def cnot(num_qubits: int, control: int, target: ) -> np.ndarray:
dim = ** num_qubits
matrix = np.eye(dim, dtype=)
i (dim):
(i >> control) & (i >> target) & :
j = i | ( << target)
k = i & ~( << target)
matrix[j, i] =
matrix[k, i] =
matrix
() -> np.ndarray:
RZ = np.array([
[np.exp(- * angle / ), ],
[, np.exp( * angle / )]
])
QuantumGate.expand_gate(RZ, num_qubits, target)
() -> np.ndarray:
dim = ** num_qubits
target < target >= num_qubits:
ValueError()
result = np.eye(, dtype=)
i (num_qubits):
i == target:
result = np.kron(result, gate)
:
result = np.kron(result, np.eye(, dtype=))
result
class QuantumSpikingNeuron:
"""
Quantum-inspired spiking neuron model.
Combines quantum mechanics with spiking neural network principles:
- Quantum superposition for input integration
- Quantum tunneling for spike generation
- Coherence time limiting neural activity
"""
def __init__(
self,
num_qubits: int = 4,
coherence_time: float = 100.0,
tunneling: float = 0.1,
threshold: float = 0.5,
) -> None:
self.num_qubits = num_qubits
self.coherence_time = coherence_time
self.tunneling = tunneling
self.threshold = threshold
self.state = QuantumState(num_qubits)
self.weights = np.random.randn(num_qubits) * 0.1
self.spike_history: list[float] = []
self.last_update: float = 0.0
def evolve(
self,
inputs: np.ndarray,
dt: float,
hamiltonian: Optional[np.ndarray] = None
) -> Tuple[np.ndarray, bool]:
"""
Evolve quantum state and potentially spike.
Args:
inputs: Input currents from connected neurons
dt: Time step in milliseconds
hamiltonian: Optional custom Hamiltonian matrix
Returns:
Tuple of (output_state, did_spike)
"""
(inputs) != .num_qubits:
ValueError()
.last_update = dt
hamiltonian :
hamiltonian = np.diag(-.weights * inputs)
evolution = expm(- * hamiltonian * dt)
.state.state = evolution @ .state.state
spike_probability = ._calculate_spike_probability()
should_spike = np.random.random() < spike_probability
should_spike:
._emit_spike()
.state.state,
.state.state,
() -> :
excited_prob = np.(np.(.state.state[ ** (.num_qubits - ):]) ** )
coherence_factor = np.exp(-.last_update / .coherence_time)
excited_prob * .tunneling * coherence_factor
() -> :
.spike_history.append(.last_update)
.state = QuantumState(.num_qubits)
._refractory_timer =
() -> :
np.(
np.arange( ** .num_qubits) *
np.(.state.state) **
)
class MultiRealityNetwork:
"""
Network that spans multiple parallel realities.
Each reality maintains its own quantum state,
and entanglement allows correlation between realities.
"""
def __init__(
self,
num_realities: int = 4,
neurons_per_reality: int = 20,
entanglement_strength: float = 0.1,
) -> None:
self.num_realities = num_realities
self.neurons_per_reality = neurons_per_reality
self.entanglement_strength = entanglement_strength
self.neurons: list[list[QuantumSpikingNeuron]] = []
self.entanglement_matrix: np.ndarray
self._initialize_network()
def _initialize_network(self) -> None:
"""Initialize neurons in each reality."""
for r in range(self.num_realities):
reality_neurons = [
QuantumSpikingNeuron(
num_qubits=4,
coherence_time=100.0,
tunneling=0.1,
)
for _ in range(self.neurons_per_reality)
]
self.neurons.append(reality_neurons)
self.entanglement_matrix = np.eye(.num_realities)
() -> [[]]:
spike_matrix = []
r (.num_realities):
reality_spikes = []
neuron .neurons[r]:
inputs = ._get_inputs(r, neuron)
_, spiked = neuron.evolve(inputs, dt)
reality_spikes.append(spiked)
spike_matrix.append(reality_spikes)
._apply_entanglement(spike_matrix)
spike_matrix
() -> np.ndarray:
inputs = np.zeros(target_neuron.num_qubits)
i, neuron (.neurons[reality]):
neuron target_neuron:
inputs[i] = neuron.get_membrane_potential()
inputs
() -> :
spike_array = np.array(spike_matrix)
i (.num_realities):
j (i + , .num_realities):
correlation = .entanglement_matrix[i, j]
correlation > :
._entangle_realities(
spike_array[i],
spike_array[j],
correlation
)
() -> :
agreement = np.(spikes_a == spikes_b) / (spikes_a)
agreement > :
adjustment = strength * ( - agreement)
agreement < :
adjustment = -strength * ( - agreement)
:
adjustment =
.entanglement_matrix = np.clip(
.entanglement_matrix + adjustment * ,
,
)