Files
physicalCombinatorics/README.md
asimonson1125 8171fc023e public-release phases 1-3: read-only public mode, gunicorn container, demo bootstrap, CI, README
- before_request guard: visitors browse + explore; writes need PHYSCOM_ADMIN_TOKEN login
- SameSite=Lax/HttpOnly cookies, persisted secret key, debug off unless FLASK_DEBUG=1
- non-root gunicorn container with healthcheck; physcom demo --if-empty on first start
- landing page Top Concepts, write controls hidden from visitors
- CI workflow, pyproject metadata, compose Ollama parity, README rewrite
- tests/test_web_access.py: access control + GET smoke test of every page

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-25 15:40:02 -05:00

126 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Physical Combinatorics
### Innovation via Attribute Mixing
[![tests](https://git.asimonson.com/andrew/physicalCombinatorics/actions/workflows/test.yml/badge.svg)](https://git.asimonson.com/andrew/physicalCombinatorics/actions)
An experiment that takes lists of real physical attributes, recombines them into every possible object, and then sorts vaguely reasonable concepts from nonsense.
Let's identify some ways of getting from here to there:
- Car
- Airplane
- Train
- Bicycle
- Walking with your legs
- Spaceship
To build a car you must choose what pushes it and what it runs on:
- Gas engine, electric motor, human pedalling, a solar sail, cannonfire recoil...
- Gasoline, lithium ion batteries, hydrogen, coal, sunlight, gunpowder...
Multiply those lists together and you get thousands of mostly novel forms of transportation: trains driven by solar sails, walking powered by tiny cannon recoil. Obviously some are more viable than others. Being pushed by a friend might work for a wheelchair, but it's far too slow for a car. So each concept is measured against target metrics (power density, cost, speed, range, cargo), weighted by what matters in a given **domain** (urban commuting cares about cost and speed; interplanetary travel cares about range).
The shortlist may include concepts that sound bizarre but are technically plausible. Bicycles, motorcycles and e-bikes all had their turn. Why not hydrogen-bikes?
The seed data is 11 platforms × 15 actuators × 18 energy storages = **2,970 combinations**, scored across 5 domains.
## How it works
Every combination goes through five passes:
1. **Constraints.** Each entity declares only its own physical envelope: what it `requires`, `provides` and `excludes`, plus numeric floors and ceilings on shared quantities like mass and footprint. The resolver cross-checks those generically across every pair. A nuclear reactor is blocked from a bicycle because its mass floor collides with the bicycle's mass ceiling, not because anyone wrote "nuclear + bicycle = no". Most of the combinatorial explosion dies here. ([why](LOGIC%20DOCS/002-guardrails-via-intrinsic-properties.md))
2. **Physics estimation.** A deterministic engine sizes each surviving combination from its entities' declared properties. It optimizes the platform/actuator/storage mass split, solves for drag-limited speed, and derives power density, range, cost and cargo. Domains can also define their own metrics as formulas.
3. **Scoring.** Raw values are log-normalized against each domain's bounds and combined with a weighted geometric mean. The geometric mean is deliberately harsh: one near-zero metric sinks the whole concept, which filters out things that are technically possible but pointless.
4. **LLM review (optional).** Top combinations get a plausibility verdict and a LOW/MEDIUM/HIGH rating from Gemini or a local Ollama model.
5. **Human review.** Annotate or approve results in the web UI.
Design reasoning lives in [`LOGIC DOCS/`](LOGIC%20DOCS/).
## Setup
### Docker (recommended)
```bash
cp .env.example .env # set PHYSCOM_ADMIN_TOKEN to be able to edit
docker compose up web
```
Open [http://localhost:5000](http://localhost:5000). On first start with an empty volume, the container seeds the transport example and scores every domain (about 20 seconds). Visitors are read-only; log in at `/login` with `PHYSCOM_ADMIN_TOKEN` to edit entities, run the pipeline or use the admin page.
CLI inside the container:
```bash
docker compose run --rm cli results urban_commuting --top 10
```
### Local development
```bash
pip install -e ".[dev,web]"
python -m physcom demo # seed + run passes 1-3 for every domain
python -m physcom_web # localhost-only dev server, no login needed
```
Then open [http://localhost:5000](http://localhost:5000). Set `FLASK_DEBUG=1` for the Werkzeug debugger (never on a reachable host).
Run tests:
```bash
python -m pytest tests/ -q
```
### LLM review (optional)
Pass 2 (physics estimation) is always the deterministic estimator, with no LLM involved.
An LLM is only used for the optional pass 4 plausibility review.
Gemini:
```bash
pip install -e ".[gemini]"
export LLM_PROVIDER=gemini
export GEMINI_API_KEY=your_key_here
# export GEMINI_MODEL=gemini-2.0-flash # optional, this is the default
physcom run urban_commuting --passes 1,2,3,4
```
Local models via [Ollama](https://ollama.com) (no extra install):
```bash
export LLM_PROVIDER=ollama
# export OLLAMA_MODEL=qwen2.5:7b # default
# export OLLAMA_HOST=http://localhost:11434 # default
physcom run urban_commuting --passes 1,2,3,4
```
Copy `.env.example` to `.env` to keep these settings.
## Deploying publicly
The container is built to sit behind a TLS-terminating reverse proxy (Caddy, nginx, or a platform like Fly.io or Railway):
- It serves with gunicorn (one worker, eight threads), runs as a non-root user and has a healthcheck.
- Anonymous visitors can browse every result and use the mass-allocation explorer, and nothing else. Every write needs a login with `PHYSCOM_ADMIN_TOKEN`. If the token is unset, nobody can write.
- Set `PHYSCOM_SECURE_COOKIES=1` once it's served over HTTPS.
- Mount a persistent volume at `/app/data`. SQLite plus a single writer is plenty for a read-mostly demo.
- To publish LLM reviews without exposing an API key: run pass 4 locally against Ollama, export from `/admin` (or `physcom snapshot export`), and import that snapshot on the server.
Minimal Caddy example:
```
physcom.example.com {
reverse_proxy localhost:5000
}
```
## Project layout
```
src/physcom/ core engine: models, SQLite repository, constraint resolver,
physics estimator, scorer, pipeline, LLM providers, CLI
src/physcom_web/ Flask + HTMX web UI
tests/ pytest suite
LOGIC DOCS/ design decisions and the reasoning behind them
```