Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ All fallback-sourced entropy is flagged in diagnostic logs so downstream analysi
| **System** | `system` | `os.urandom()` — OS cryptographic RNG (fallback/testing) |
| **Timing noise** | `timing_noise` | CPU timing jitter (experimental) |
| **Mock uniform** | `mock_uniform` | Configurable test source with seed/bias |
| **OpenEntropy** | `openentropy` | 63 hardware noise sources (thermal, timing, microarch, GPU) — local, no network |

### Fallback behavior

Expand All @@ -367,6 +368,38 @@ Configure with `QR_FALLBACK_MODE`:
- `mock_uniform` — fall back to the mock source
- `error` — raise immediately, no fallback

### OpenEntropy

[OpenEntropy](https://github.com/amenti-labs/openentropy) harvests entropy from 63 hardware noise sources on the local machine — thermal sensors, CPU timing jitter, memory timing, GPU scheduling, and more. No network, no API keys, no gRPC server needed.

Install:

```bash
pip install openentropy
```

Configure:

```bash
export QR_ENTROPY_SOURCE_TYPE=openentropy
export QR_OE_CONDITIONING=raw # raw (research default) | vonneumann | sha256
```

List available sources on your machine:

```python
from openentropy import detect_available_sources
print([s["name"] for s in detect_available_sources()])
```

To sample from specific sources only, set `QR_OE_SOURCES` to a comma-separated list:

```bash
export QR_OE_SOURCES=clock_jitter,dram_row_buffer
```

See [`deployments/openentropy/`](deployments/openentropy/) for the full deployment profile.

### Third-party entropy sources

Any Python package can register entropy sources via entry points:
Expand Down
49 changes: 49 additions & 0 deletions deployments/openentropy/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# deployments/openentropy/.env
#
# Environment variables for the OpenEntropy native entropy profile.
# Copy this file to .env and edit as needed:
# cp .env.example .env

# --- Hugging Face ---
# Model to serve. Default: Qwen/Qwen2.5-1.5B-Instruct
HF_MODEL=Qwen/Qwen2.5-1.5B-Instruct
# Set this if the model is gated (requires accepting a license).
HF_TOKEN=

# --- Entropy source ---
# OpenEntropy: local hardware entropy (no Docker, native only)
# 63 hardware noise sources: thermal, timing, microarch, GPU, etc.
# Install: pip install openentropy
# Docs: https://github.com/amenti-labs/openentropy
QR_ENTROPY_SOURCE_TYPE=openentropy

# Conditioning mode: raw (research default), vonneumann (debiased), sha256 (crypto)
QR_OE_CONDITIONING=raw

# Comma-separated list of source names to use. Empty = all available sources.
QR_OE_SOURCES=

# Enable parallel collection from multiple sources (faster, more entropy).
QR_OE_PARALLEL=true

# Timeout in seconds for entropy collection.
QR_OE_TIMEOUT=5.0

# Fall back to system entropy if OpenEntropy is unavailable.
QR_FALLBACK_MODE=system

# --- Sampling parameters ---
QR_SAMPLE_COUNT=20480
QR_TEMPERATURE_STRATEGY=fixed
QR_FIXED_TEMPERATURE=0.7
QR_TOP_K=0
QR_TOP_P=1.0
QR_LOG_LEVEL=summary

# --- Ports (host-side) ---
VLLM_PORT=8000

# --- Open WebUI (optional, --profile ui) ---
OPEN_WEBUI_PORT=3000
# Set to true to require login (recommended for shared/public servers).
OPEN_WEBUI_AUTH=false
128 changes: 128 additions & 0 deletions deployments/openentropy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# OpenEntropy Profile

Runs vLLM with qr-sampler using **OpenEntropy** — a local hardware entropy
source that collects noise from 63 hardware sources on Apple Silicon (thermal,
timing, microarchitecture, GPU, etc.). This is a **native-only profile** — no
Docker, no network dependency.

## Why not Docker?

Docker containers cannot access Metal GPU or native hardware entropy sources on
macOS. Apple's Virtualization.framework has no GPU passthrough, and hardware
noise sources (thermal sensors, CPU timing, GPU state) are not exposed to
containerized processes. OpenEntropy requires native execution.

## Quick start

1. Install OpenEntropy and qr-sampler:

```bash
pip install openentropy
pip install -e /path/to/qr-sampler
```

2. Configure your environment:

```bash
cd deployments/openentropy
cp .env.example .env
```

Edit `.env` if needed — set `HF_TOKEN` if using a gated model.

3. Start vLLM:

```bash
source .env
vllm serve $HF_MODEL \
--port $VLLM_PORT \
--logits-processors qr_sampler
```

## Available entropy sources

OpenEntropy provides 63 entropy sources across 13 categories. For the full
catalog with physics explanations, see the
[OpenEntropy Source Catalog](https://github.com/amenti-labs/openentropy/blob/master/docs/SOURCES.md).

List all available sources on your hardware:

```bash
python -c "from openentropy import detect_available_sources; print([s['name'] for s in detect_available_sources()])"
```

Sources span thermal, timing, microarchitecture, GPU, IPC, scheduling, and more.
Some notable ones for research:

| Source | Category | Physical mechanism |
|--------|----------|-------------------|
| `counter_beat` | Thermal | CPU counter vs audio PLL crystal beat frequency |
| `dual_clock_domain` | Microarch | 24 MHz x 41 MHz independent oscillator beat |
| `gpu_divergence` | GPU | Shader warp execution order divergence |
| `dvfs_race` | Microarch | Cross-core DVFS frequency race |
| `clock_jitter` | Timing | Timing jitter between readout paths |
| `dram_row_buffer` | Timing | DRAM row buffer hit/miss timing |

To sample from a specific source, set `QR_OE_SOURCES`:

```bash
export QR_OE_SOURCES=counter_beat
```

## Conditioning modes

OpenEntropy supports three conditioning strategies:

| Mode | Use case | Properties |
|------|----------|-----------|
| `raw` | Research (default) | Preserves hardware noise signal; minimal processing |
| `vonneumann` | Debiased entropy | Von Neumann debiasing; slower, more uniform |
| `sha256` | Cryptographic | SHA-256 hashing; suitable for security-critical applications |

Set `QR_OE_CONDITIONING` in `.env` or override per-request:

```python
# Per-request override
extra_args = {"qr_oe_conditioning": "sha256"}
```

## Parallel collection

By default, `QR_OE_PARALLEL=true` collects from multiple sources simultaneously,
increasing entropy throughput. Set to `false` for sequential collection (slower,
lower memory overhead).

## When to use this profile

- **Consciousness research**: Study whether intent influences quantum-random
processes using native hardware entropy.
- **Local experiments**: No network latency, no external dependencies.
- **Apple Silicon development**: Leverage Metal GPU and native hardware sensors.
- **Research baseline**: Compare hardware entropy against system entropy
(`/dev/urandom`).

## Web UI (optional)

This profile includes [Open WebUI](https://github.com/open-webui/open-webui), a
ChatGPT-style web interface. To use it, you'll need to run it separately (not
included in this native profile):

```bash
docker run -d -p 3000:3000 --name open-webui ghcr.io/open-webui/open-webui:latest
```

Then point it at your vLLM instance running on `localhost:8000`.

A pre-built filter function for controlling qr-sampler parameters from the UI is
available at [`examples/open-webui/`](../../examples/open-webui/). See that
directory's README for import instructions.

## Next steps

Once this profile works, you can:
1. Adjust `QR_OE_SOURCES` to use specific entropy sources.
2. Experiment with different conditioning modes (`raw`, `vonneumann`, `sha256`).
3. Compare results against the `urandom` profile (gRPC-based) or `system` profile
(fallback).
4. Browse the full [OpenEntropy Source Catalog](https://github.com/amenti-labs/openentropy/blob/master/docs/SOURCES.md)
for detailed physics explanations of each entropy source.
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dev = [
"pre-commit>=4.0",
"bandit>=1.8.0",
]
openentropy = [
"openentropy>=0.10.0",
]

[project.entry-points."vllm.logits_processors"]
qr_sampler = "qr_sampler.processor:QRSamplerLogitsProcessor"
Expand All @@ -55,6 +58,7 @@ system = "qr_sampler.entropy.system:SystemEntropySource"
quantum_grpc = "qr_sampler.entropy.quantum:QuantumGrpcSource"
timing_noise = "qr_sampler.entropy.timing:TimingNoiseSource"
mock_uniform = "qr_sampler.entropy.mock:MockUniformSource"
openentropy = "qr_sampler.entropy.openentropy:OpenEntropySource"

[tool.setuptools.packages.find]
where = ["src"]
Expand Down Expand Up @@ -98,6 +102,10 @@ ignore_missing_imports = true
module = ["torch", "torch.*"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "openentropy.*"
ignore_missing_imports = true

[tool.coverage.run]
source = ["src/qr_sampler"]
omit = [
Expand Down
2 changes: 2 additions & 0 deletions src/qr_sampler/amplification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"""

from qr_sampler.amplification.base import AmplificationResult, SignalAmplifier
from qr_sampler.amplification.ecdf import ECDFAmplifier
from qr_sampler.amplification.registry import AmplifierRegistry
from qr_sampler.amplification.zscore import ZScoreMeanAmplifier

__all__ = [
"AmplificationResult",
"AmplifierRegistry",
"ECDFAmplifier",
"SignalAmplifier",
"ZScoreMeanAmplifier",
]
Loading
Loading