Skip to content

Repository files navigation

BrepBloom

BrepBloom is a corpus-guided CAD construction-program generator and model foundry. It generates typed CAD histories, executes them through an external geometric-kernel backend, and uses the kernel as the validity oracle rather than trying to hand-code every geometric validity rule.

The initial backend is parasolid-rs. The primary corpus target is CADFS/ABC: real FeatureScript construction histories are imported into BrepBloom's stable IR, mined for feature grammar and parameter distributions, mutated/crossed over, executed by Parasolid, reduced when they fail, and exported as state/action trajectories for models such as KernelFormer.

The project name reflects the intended workflow: a small population of valid CAD programs is repeatedly mutated and recombined until it blooms into a large, diverse B-rep corpus.

What is implemented

The workspace is split so almost all processing runs without a CAD license or even a kernel installed:

  • brepbloom-ir — typed kernel-independent construction-history IR, selectors/provenance, validation, complexity metrics, stable BBP/1 text serialization.
  • brepbloom-cadfs — tolerant cleaned-FeatureScript/CADFS importer with balanced syntax scanning, sketch reconstruction, common query recovery, unit normalization, and lossless opaque fallbacks.
  • brepbloom-corpus — operation counts, transition grammar, 2–5 feature motifs, construction-length statistics, and numerical parameter moments.
  • brepbloom-gen — deterministic corpus-conditioned generation, adversarial parameter excursions, typed mutations, crossover with ID remapping, and dangling-reference repair.
  • brepbloom-backend — process-isolated backend protocol and per-feature topology/mass/bounds traces.
  • brepbloom-diff — per-feature and final-state trace comparison with exact topology counts plus tolerant numerical invariants.
  • brepbloom-reduce — ddmin feature deletion, dependency repair, parameter shrinking, and earliest-failing-prefix search.
  • brepbloom-search — evolutionary backend-guided search that accepts only kernel-valid offspring and optimizes actual B-rep complexity.
  • brepbloom-dataset — prefix-level state/history/action JSONL export for autoregressive CAD-policy training.
  • brepbloom — CLI tying the whole pipeline together.
  • integrations/parasolid-runner — out-of-process Parasolid executor using parasolid-rs.
  • scripts/apply_parasolid_extensions.py — idempotent high-level parasolid-rs compatibility patch for planar-wire covering and chamfers.

The Parasolid runner handles analytic primitives, planar sketches made from lines/circles/arcs/ellipses/non-periodic B-curves, common nested multi-loop profiles (outer regions, holes, and islands), extrusion, revolution, booleans, fillets, constant-offset chamfers, simple/counterbored/countersunk holes, closed shelling, transforms, mirrors, circular patterns, deletion/construction records, validity checks, topology summaries, mass properties, bounding boxes, and optional per-step XT export.

Some FeatureScript semantics are intentionally represented but not silently approximated by the current Parasolid lowering. General path sweeps, lofts, drafted extrusion, face-derived sketch frames, pierced shelling, angle chamfers, and unresolved CADFS queries are reported as unsupported in the execution trace. See docs/FEATURE_COVERAGE.md. This is deliberate: wrong geometry is worse training data than an explicit unsupported record.

Quick start: core workspace

Rust 1.85 or later is required because the workspace uses edition 2024.

cargo test --workspace
cargo run -p brepbloom -- help

# Import a cleaned CADFS FeatureScript file.
cargo run -p brepbloom -- import-cadfs fixtures/basic.fs --out /tmp/basic.bbp
cargo run -p brepbloom -- inspect /tmp/basic.bbp

# Exercise orchestration without a geometric kernel.
cargo run -p brepbloom -- execute /tmp/basic.bbp --mock --trace /tmp/basic.bbtrace

# Generate and mutate programs.
cargo run -p brepbloom -- generate --seed 42 --out /tmp/generated.bbp
cargo run -p brepbloom -- mutate /tmp/generated.bbp --kind add-boolean --seed 43 --out /tmp/mutated.bbp

The mock backend exists only to test plumbing. It is never geometric evidence.

Connect parasolid-rs

The runner intentionally stays out of the main Cargo workspace because it needs the licensed Parasolid runtime and a local parasolid-rs checkout.

Assuming sibling checkouts:

work/
  brepbloom/
  parasolid-rs/

run:

cd brepbloom
./scripts/link_parasolid.sh ../parasolid-rs
python3 scripts/apply_parasolid_extensions.py ../parasolid-rs

cargo build --manifest-path integrations/parasolid-runner/Cargo.toml --release

The patch adds only two high-level conveniences missing from the current safe API: Edge::make_planar_sheet and Body::chamfer_edges. It does not alter parasolid-sys or add new FFI declarations.

Then execute a model:

cargo run -p brepbloom -- execute examples/demo.bbp \
  --backend integrations/parasolid-runner/target/release/brepbloom-parasolid-runner \
  --trace /tmp/demo.bbtrace \
  --export-dir /tmp/demo-xt

--export-dir asks the runner to transmit the latest bodies after each successful feature, giving you concrete Parasolid XMT artifacts to inspect rather than merely trusting counters.

CADFS → corpus → generator

For a downloaded CADFS featurescript_rp tree:

cargo run -p brepbloom -- batch-import data/featurescript_rp --out data/programs
cargo run -p brepbloom -- mine data/programs --out data/cadfs.bbcorpus

cargo run -p brepbloom -- generate \
  --corpus data/cadfs.bbcorpus \
  --seed 1001 --min 25 --max 80 --score 100 \
  --out /tmp/seed.bbp

The corpus model is intentionally simple before ML enters the loop: empirical next-operation transitions, feature motifs, and parameter moments. This gives a debuggable baseline and provides seeds for a learned proposal policy later.

Kernel-guided complexity search

The central automation is search. Start with any known-valid program and let Parasolid decide which mutations survive:

cargo run -p brepbloom -- search /tmp/seed.bbp \
  --backend integrations/parasolid-runner/target/release/brepbloom-parasolid-runner \
  --attempts 5000 \
  --population 48 \
  --target 800 \
  --archive /tmp/bloom-run \
  --out /tmp/best.bbp \
  --best-trace /tmp/best.bbtrace

Each offspring is generated with a typed mutation, run in a separate backend process, rejected on kernel failure or B-rep invalidity, and scored using both program complexity and actual topology counts. Accepted/failing programs and traces can be archived. This makes Parasolid the constraint solver instead of encoding a giant list of special-case CAD rules.

The current mutation vocabulary includes numerical jitter, fillet/chamfer/hole/shell insertion, circular patterns, analytic boolean-tool insertion, transforms, and dependency-safe leaf deletion. brepbloom-gen::crossover also grafts donor history tails with feature-ID and selector remapping.

Failure reduction

Kernel failures are useful data. Reduce them automatically:

cargo run -p brepbloom -- reduce /tmp/failing.bbp \
  --backend integrations/parasolid-runner/target/release/brepbloom-parasolid-runner \
  --out /tmp/minimal-repro.bbp

The reducer first removes chunks of feature history while repairing references, then shrinks numerical parameters while preserving the failure predicate. brepbloom-reduce also exposes earliest-failing-prefix search for feature-by-feature compiler work.

Differential oracles

Every backend writes BBTRACE/1. This makes Parasolid, CADabra, OpenCascade, or an Onshape reference executor interchangeable at the comparison layer:

cargo run -p brepbloom -- diff parasolid.bbtrace reference.bbtrace

The comparison uses validity, body/region/shell/face/edge/vertex counts, volume/measure, boundary area/periphery, and bounding boxes. The protocol has an artifact field so a backend can additionally retain XT/STEP/mesh output for deeper comparison and human inspection.

KernelFormer trajectory generation

After executing imported/generated programs, arrange traces with the same relative paths as programs and run:

cargo run -p brepbloom -- dataset data/programs data/traces \
  --out data/kernelformer-trajectories.jsonl

Each record contains:

  • construction history before the action;
  • the geometric snapshot before the action;
  • the exact typed action serialized as a BBP/1 feature record;
  • the resulting geometric snapshot.

This yields the behavior-cloning form:

(BRep/state summary, feature history) -> next CAD operation

The state schema is deliberately compact today. A future B-rep graph exporter can add face/edge geometry embeddings while retaining this record framing.

Data formats

BBP/1 is a stable line-oriented construction-program format designed for diffs, reducers, and agent inspection. BBCORPUS/1 stores mined statistics. BBTRACE/1 stores backend execution outcomes. The training exporter uses JSONL because it is convenient for model pipelines.

None of these formats contains opaque Parasolid handles. Feature references are semantic/provenance selectors, so programs survive process boundaries and can target multiple kernels.

Design principles

  1. Generate programs, not B-reps. The kernel owns topology construction.
  2. Treat real CAD histories as grammar. CADFS supplies realistic feature order, parameter, and selector priors.
  3. Let execution reject bad proposals. Do not reimplement every local geometric constraint in the generator.
  4. Never hide unsupported semantics. Preserve raw corpus information and make lowering gaps explicit.
  5. Make every failure reducible and reproducible. Seeds, programs, traces, and artifacts are first-class.
  6. Keep proprietary kernels out of corpus workers. Backends are process isolated.
  7. Measure actual geometry. Complexity is not merely feature count.
  8. Require observation. The validation procedure explicitly opens/inspects generated geometry; green unit tests are insufficient.

Read docs/ARCHITECTURE.md for the detailed dataflow, BUILD_STATUS.md for what was actually verified while assembling this artifact, and AGENT_TESTING.md for the required end-to-end validation protocol.

Inspect an existing Parasolid reference B-rep

The integration package also builds inspect_xmt. With the current parasolid-rs default frustrum, the key abc_000123 resolves to abc_000123.xmt_txt under --base-dir.

cargo run --manifest-path integrations/parasolid-runner/Cargo.toml \
  --bin inspect_xmt -- \
  --base-dir /data/abc-xmt \
  --key abc_000123 \
  --trace /tmp/abc_000123.bbtrace

cargo run -p brepbloom -- diff \
  /tmp/replayed.bbtrace /tmp/abc_000123.bbtrace --final-only

This is the coarse invariant comparison path; topology correspondence and sampled face/edge geometry remain the next differential layer.

About

Corpus-guided CAD construction-program generator that uses geometric kernels as validity oracles and exports B-rep training trajectories.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages