CLI¶
Command-line interface built with Typer, installed as urbansolarcarver and its short alias usc. Provides the same 3-stage pipeline as the Python API, plus daemon management, config validation and introspection, and the simulated-weights tools.
# Run the whole pipeline
urbansolarcarver run -c config.yaml
# Produce the floor plates too, or reuse the scores and re-threshold
urbansolarcarver run -c config.yaml --produce exporting --produce massing
urbansolarcarver run -c config.yaml --start-from thresholding -o carve_fraction=0.5
# Run pipeline stages
urbansolarcarver preprocessing -c config.yaml
urbansolarcarver thresholding -c config.yaml -f outputs/preprocessing/manifest.json
urbansolarcarver exporting -c config.yaml -f outputs/thresholding/manifest.json
# Override any config value on the fly
urbansolarcarver preprocessing -c config.yaml -o voxel_size=0.5 -o mode=irradiance
# Check a config without running anything
urbansolarcarver validate -c config.yaml
# Build and validate a building archetype (prints derived areas)
urbansolarcarver archetype -o my_building.yaml -s width=12 -s wwr_south=0.4 -s mass_class=heavy
# Generate simulated benefit weights (writes simulated_weights.json + .png preview)
urbansolarcarver simulate-weights -e weather.epw -a my_building.yaml
# List the config parameters (optionally --mode benefit or --search threshold)
urbansolarcarver schema
# Precompile the Warp kernels
urbansolarcarver warmup
# Daemon lifecycle
urbansolarcarver daemon start
urbansolarcarver daemon status
urbansolarcarver daemon stop
Without -f, thresholding and exporting look for the previous stage's manifest.json under the config's out_dir.
run takes --produce (repeatable; preprocessing, thresholding, exporting or massing; default exporting) and runs the stages those need. --start-from (default preprocessing) skips the stages before it and reads their output from <out>/<stage>. Both work with --daemon, which sends the daemon's run command.
Issues noticed during a command (settings the mode ignores, nothing carved, ...) print after the result under Issues: as stage: code: message. A package error (an invalid config, an unusable input file, a missing or stale upstream output) prints Error: <message> and exits with 1, without a traceback.
urbansolarcarver.carver_cli
¶
UrbanSolarCarver command-line interface.
Exposes the pipeline stages (preprocessing, thresholding, exporting, massing)
as individual subcommands, plus run, which runs the stages needed for what
--produce asks for (the carved mesh by default).
Performance evaluation is out of scope: use Ladybug/Honeybee/Radiance on the
exported mesh.
Utility commands:
- warmup: precompile the Warp kernels once so the first run is not slow.
- simulate-weights: build a simulated-weights file for benefit mode.
- archetype: write and check a shoebox archetype YAML for simulate-weights.
- validate: load and validate a YAML config without running anything.
- schema: print a filterable parameter reference (by mode or keyword).
- daemon: start / stop / status of the persistent GPU daemon used by
Grasshopper and the --daemon flag on pipeline commands.
Design decisions
~~~~~~~~~~~~~~~~
All heavy imports (torch, warp, api_core) are deferred to function bodies so
that lightweight commands (--help, schema, validate, daemon)
start quickly without initialising CUDA or compiling Warp kernels.
Pipeline commands import urbansolarcarver.api inside their bodies, and
the daemon commands use the standard-library daemon_client.
The --daemon flag on each pipeline command sends the job to a running
daemon over localhost TCP (multiprocessing.connection), sharing the same
RPC mechanism used by the Grasshopper plugin.
main(ctx, version=Option(False, '--version', '-V', callback=_version_callback, is_eager=True, help='Show version and exit'), quiet=Option(False, '--quiet', '-q', help='Suppress torch/warp banners and non-essential output'))
¶
GPU-accelerated solar envelope generation for urban design.
run(config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config KEY=VALUE'), out_dir=Option(None, '--out', help='Run folder (one subfolder per stage)'), produce=Option([], '--produce', help='Stage to produce: preprocessing, thresholding, exporting or massing (repeatable; default exporting)'), start_from=Option('preprocessing', '--start-from', help='First stage to run; the stage before it is read from the run folder'), daemon=Option(False, '--daemon', help='Send to running daemon instead of running locally'), quiet=Option(False, '-q', '--quiet', help='Minimal output'))
¶
Run the stages needed to produce what --produce names.
With no --produce this chains preprocessing, thresholding and
exporting into <out>/preprocessing, <out>/thresholding and
<out>/exporting. --produce massing runs preprocessing,
thresholding and massing; both together threshold once. With
--start-from thresholding the scores already in <out>/preprocessing
are reused, which is the way to iterate on threshold parameters without
recomputing them.
A config with a criteria: list is a chain: the criteria are carved one
after the other on one voxel grid, each deciding only among the voxels the
one before kept, and exporting and massing build from the last. Each
criterion's stages go to <out>/criteria/<id>/preprocessing and
<out>/criteria/<id>/thresholding. --override then sets shared
settings only (meshes, voxel size, out_dir, exporting, massing).
cmd_preprocessing(config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config fields'), out_dir=Option(None, '--out', help='Output directory'), daemon=Option(False, '--daemon', help='Send to running daemon'), quiet=Option(False, '-q', '--quiet', help='Minimal output'), dry_run=Option(False, '--dry-run', help='Estimate grid size and memory, then exit without running'))
¶
Voxelize, sample surfaces, trace rays, and write scores.
Outputs scores.npy, voxel_grid.npy, and manifest.json into
the output directory. The manifest is consumed by the thresholding stage.
cmd_thresholding(from_manifest=Option(None, '-f', '--from', help='Path to preprocessing manifest.json (auto-detected if omitted)'), config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config fields'), after=Option(None, '--after', exists=True, readable=True, help='Thresholding folder or manifest.json of the previous criterion: decide only among the voxels it kept'), out_dir=Option(None, '--out', help='Output directory'), daemon=Option(False, '--daemon', help='Send to running daemon'), quiet=Option(False, '-q', '--quiet', help='Minimal output'))
¶
Apply the configured threshold to the preprocessing scores.
Reads the preprocessing manifest (-f) to locate scores.npy,
applies the threshold from the config to the occupied voxels, and writes
mask.npy (True = voxel kept).
This is the cheapest stage and is meant for quick iteration. Re-run with
different -o threshold=... or -o carve_fraction=... values without
recomputing scores.
With --after the threshold applies only to the voxels the previous
criterion's thresholding kept (one step of a chain; run does the whole
chain from a config with criteria:).
cmd_exporting(from_manifest=Option(None, '-f', '--from', help='Path to thresholding manifest.json (auto-detected if omitted)'), config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config fields'), out_dir=Option(None, '--out', help='Output directory'), daemon=Option(False, '--daemon', help='Send to running daemon'), quiet=Option(False, '-q', '--quiet', help='Minimal output'))
¶
Reconstruct a triangle mesh from the binary carving mask.
Reads the thresholding manifest (-f) to locate mask.npy,
prunes small disconnected clusters, reconstructs a triangle mesh
(cubic faces or SDF-smoothed marching cubes), and writes
export.<format> (format from final_mesh_format, default ply).
cmd_massing(from_manifest=Option(None, '-f', '--from', help='Path to thresholding manifest.json (auto-detected if omitted)'), config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config fields'), out_dir=Option(None, '--out', help='Output directory'), daemon=Option(False, '--daemon', help='Send to running daemon'), quiet=Option(False, '-q', '--quiet', help='Minimal output'))
¶
Build stacked floor plates that follow the footprint, from the carving mask.
Reads the thresholding manifest (-f) and writes plates.json
(outlines in world coordinates) and plates.obj (one closed prism per
plate), and the same plates as plates.<format> when final_mesh_format
is not obj. Settings: ground_floor_height, floor_height,
min_plate_dimension, plate_tolerance, plate_stacking, final_mesh_format.
warmup(device=Option('auto', '--device', '-d', help="Target device: 'auto', 'cpu', or 'cuda'"))
¶
Compile the Warp compute kernels ahead of time.
Warp compiles kernels just in time on first use, a one-time cost of
roughly 3-10 s per machine, device and code version that is cached on
disk afterwards. Run this once after installing or updating
UrbanSolarCarver so the first carving run reflects real compute time.
(setup_env.py and the daemon do this automatically.) Exits with
code 1 if the Warp backend is not available on the device.
simulate_weights(epw=Option(..., '-e', '--epw', exists=True, readable=True, help='EPW weather file'), archetype=Option(..., '-a', '--archetype', exists=True, readable=True, help='Archetype YAML (see configs/archetype_example.yaml)'), out=Option(Path('simulated_weights.json'), '-o', '--out', help='Output artifact path'), eps=Option(1.0, '--eps', help='Perturbation size in W (central differences)'))
¶
Write a simulated-weights file for benefit mode.
Runs the ISO 13790 Annex C simple hourly model (5R1C: five resistances,
one capacitance) for the archetype and weather file, perturbs the solar
gain by +/- eps W each hour, and records the hourly marginal benefit
and harm of solar gain (central differences).
The file is read through benefit mode's simulated_weights_path config
key, where it replaces the balance-point on/off hour filter with these
hourly weights. See docs/simulated-weights.md.
archetype(out=Option(Path('archetype.yaml'), '-o', '--out', help='Output archetype YAML path'), set_=Option([], '-s', '--set', help='Override a field, e.g. -s width=12 -s wwr_south=0.4 -s mass_class=heavy'), from_=Option(None, '--from', help='Start from an existing shoebox archetype YAML instead of defaults'), force=Option(False, '--force', help='Overwrite the output file if it exists'))
¶
Build a shoebox archetype, validate it, and report derived quantities.
The file is validated through the same code path the generator uses
(expand_shoebox + ZoneParams.from_archetype) before writing, and
the derived floor area, volume, and per-facade window areas are printed
so mistakes surface here rather than inside a simulation.
Only the shoebox form is built by this command; explicit-area archetypes are edited directly in YAML (see configs/archetype_example.yaml).
validate(config=Option(..., '-c', '--config', exists=True, readable=True, help='YAML config path'), override=Option([], '-o', '--override', help='Override config fields'))
¶
Parse and validate the YAML config through Pydantic.
Exits with code 1 if the config fails schema or value checks. Missing mesh (context and terrain included), EPW and simulated-weights files, and a simulated-weights file that cannot be read, are printed as warnings only (exit code 0). Does not initialise CUDA or import torch.
A config with a criteria: list is a chain: every criterion is
validated and listed on a line of its own, with the settings the
criteria share printed once.
schema(mode=Option(None, '--mode', '-m', help='Show only parameters relevant to this mode'), search=Option(None, '--search', '-s', help='Filter parameters by name or description substring'))
¶
Print the full UserConfig parameter table.
Reads field metadata from the Pydantic schema, so no heavy imports are needed.
Filter by mode (--mode benefit) to see only the parameters that mode
uses, or search by keyword (--search threshold).
ui(port=Option(UI_DEFAULT_PORT, '--port', help='Port on 127.0.0.1'), projects_folder=Option(None, '--projects-folder', help='Folder that holds one subfolder per project (default: the folder chosen in the app, else ~/UrbanSolarCarver/projects)'), no_browser=Option(False, '--no-browser', help='Print the address without opening the browser'), device=Option('auto', '--device', '-d', help="Compute device: 'auto', 'cpu', or 'cuda'"))
¶
Start the local web service and open the interface in the default browser.
The service listens on 127.0.0.1 only. Each launch creates a random token, which the browser receives once in the address and sends with every request; the address is printed here as well. The compute kernels are compiled in the background while the interface is used. Press Ctrl+C to stop.
daemon_start(foreground=Option(False, '-F', '--foreground', help='Run daemon in this console (blocks)'), python=Option(None, '--python', help='Python interpreter to use for the daemon process'))
¶
Start the GPU daemon as a detached background process.
Does nothing if a daemon already answers on the port. Detached runs use
pythonw.exe on Windows (no console window, unless --python is
given) and write their output to ~/.urbansolarcarver/daemon.log,
which is overwritten on each start. -F runs in this console instead,
which is useful for debugging. A detached start polls once per second,
for up to 30 s, until the daemon answers a ping, and exits with code 1 if
it does not.
daemon_stop()
¶
Send a shutdown command to the running daemon.
daemon_status()
¶
Ping the daemon and print its pid; exit with code 1 if it does not answer.