pitopt 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pitopt/__init__.py +15 -0
- pitopt/__main__.py +7 -0
- pitopt/cli.py +207 -0
- pitopt/config.py +530 -0
- pitopt/core/__init__.py +1 -0
- pitopt/core/cancel.py +32 -0
- pitopt/core/design.py +475 -0
- pitopt/core/design_detail/__init__.py +5 -0
- pitopt/core/design_detail/angles.py +100 -0
- pitopt/core/design_detail/builder.py +230 -0
- pitopt/core/design_detail/config.py +416 -0
- pitopt/core/design_detail/footprint.py +199 -0
- pitopt/core/design_detail/offset.py +114 -0
- pitopt/core/design_detail/parameters.py +336 -0
- pitopt/core/design_detail/ramp.py +533 -0
- pitopt/core/design_detail/reconcile.py +210 -0
- pitopt/core/design_detail/stack.py +245 -0
- pitopt/core/design_detail/validate.py +198 -0
- pitopt/core/economics.py +245 -0
- pitopt/core/limits.py +136 -0
- pitopt/core/pitsurface.py +108 -0
- pitopt/core/planning.py +223 -0
- pitopt/core/precedence.py +486 -0
- pitopt/core/reblock.py +272 -0
- pitopt/core/reserves.py +339 -0
- pitopt/core/schedule.py +360 -0
- pitopt/core/sensitivity.py +100 -0
- pitopt/core/shells.py +100 -0
- pitopt/core/solver.py +182 -0
- pitopt/core/verify.py +310 -0
- pitopt/io/__init__.py +3 -0
- pitopt/io/blockmodel.py +210 -0
- pitopt/io/console.py +75 -0
- pitopt/io/datasets.py +204 -0
- pitopt/io/datfile.py +93 -0
- pitopt/io/design_export.py +360 -0
- pitopt/io/dxf.py +259 -0
- pitopt/io/excel.py +231 -0
- pitopt/io/pdf.py +376 -0
- pitopt/io/plot.py +66 -0
- pitopt/io/results.py +594 -0
- pitopt/io/viz.py +371 -0
- pitopt/mcp_server.py +632 -0
- pitopt/pipeline.py +1022 -0
- pitopt/provenance.py +62 -0
- pitopt/ui/__init__.py +3 -0
- pitopt/ui/design_service.py +412 -0
- pitopt/ui/mcp_controller.py +509 -0
- pitopt/ui/onboard.py +403 -0
- pitopt/ui/server.py +1145 -0
- pitopt/ui/staging.py +49 -0
- pitopt/ui/static/css/app.css +301 -0
- pitopt/ui/static/css/chat.css +657 -0
- pitopt/ui/static/css/design.css +62 -0
- pitopt/ui/static/fonts/IBMPlexMono-400.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexMono-500.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexMono-600.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexSans-var.woff2 +0 -0
- pitopt/ui/static/fonts/OFL.txt +93 -0
- pitopt/ui/static/i18n/en.json +1229 -0
- pitopt/ui/static/img/design.webp +0 -0
- pitopt/ui/static/img/og-pitopt-2026-11.png +0 -0
- pitopt/ui/static/img/pitbypit.webp +0 -0
- pitopt/ui/static/img/pushback.webp +0 -0
- pitopt/ui/static/img/summary.webp +0 -0
- pitopt/ui/static/img/tutorial-marvin.webp +0 -0
- pitopt/ui/static/index.html +24 -0
- pitopt/ui/static/js/actions.js +4 -0
- pitopt/ui/static/js/app.js +223 -0
- pitopt/ui/static/js/charts.js +279 -0
- pitopt/ui/static/js/chat-panel.js +1210 -0
- pitopt/ui/static/js/commands.js +1025 -0
- pitopt/ui/static/js/csp-boot.js +48 -0
- pitopt/ui/static/js/design/core.js +194 -0
- pitopt/ui/static/js/design/plan.js +105 -0
- pitopt/ui/static/js/design/planview.js +49 -0
- pitopt/ui/static/js/design/section.js +80 -0
- pitopt/ui/static/js/design/three.js +45 -0
- pitopt/ui/static/js/design/ui.js +175 -0
- pitopt/ui/static/js/i18n.js +205 -0
- pitopt/ui/static/js/manage.js +119 -0
- pitopt/ui/static/js/modal.js +16 -0
- pitopt/ui/static/js/run.js +81 -0
- pitopt/ui/static/js/store.js +103 -0
- pitopt/ui/static/js/tutorial-guide.js +140 -0
- pitopt/ui/static/js/util.js +98 -0
- pitopt/ui/static/js/views/blocks.js +106 -0
- pitopt/ui/static/js/views/common.js +37 -0
- pitopt/ui/static/js/views/design_ekspor.js +69 -0
- pitopt/ui/static/js/views/design_generate.js +76 -0
- pitopt/ui/static/js/views/design_penampang.js +72 -0
- pitopt/ui/static/js/views/design_ramp.js +109 -0
- pitopt/ui/static/js/views/design_sektor.js +117 -0
- pitopt/ui/static/js/views/design_sumber.js +75 -0
- pitopt/ui/static/js/views/design_validasi.js +88 -0
- pitopt/ui/static/js/views/misc.js +128 -0
- pitopt/ui/static/js/views/params.js +189 -0
- pitopt/ui/static/js/views/pitbypit.js +65 -0
- pitopt/ui/static/js/views/plan.js +140 -0
- pitopt/ui/static/js/views/summary.js +94 -0
- pitopt/ui/static/js/views/upload.js +503 -0
- pitopt/ui/static/js/views/view3d.js +85 -0
- pitopt/ui/static/js/views/workspace.js +103 -0
- pitopt/ui/static/landing.html +487 -0
- pitopt-1.1.0.dist-info/METADATA +180 -0
- pitopt-1.1.0.dist-info/RECORD +112 -0
- pitopt-1.1.0.dist-info/WHEEL +5 -0
- pitopt-1.1.0.dist-info/entry_points.txt +3 -0
- pitopt-1.1.0.dist-info/licenses/LICENSE +661 -0
- pitopt-1.1.0.dist-info/licenses/NOTICE +19 -0
- pitopt-1.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +52 -0
- pitopt-1.1.0.dist-info/top_level.txt +1 -0
pitopt/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
# Copyright (c) 2026 Orebit (Ghozian Islam Karami)
|
|
3
|
+
"""
|
|
4
|
+
pitopt — open-pit ultimate pit limit optimisation.
|
|
5
|
+
|
|
6
|
+
Block model (CSV) + topography (DXF) in; nested revenue-factor shells,
|
|
7
|
+
discounted pit-by-pit, the final pit chosen on NPV, pushbacks, a period
|
|
8
|
+
mine plan and a benched pit design out — as Excel, DXF and an HTML 3D
|
|
9
|
+
viewer. Each shell is a maximum closure solved exactly with NetworkX preflow-push.
|
|
10
|
+
"""
|
|
11
|
+
from .config import ProjectConfig
|
|
12
|
+
from .pipeline import PitResult, run
|
|
13
|
+
|
|
14
|
+
__all__ = ["ProjectConfig", "PitResult", "run"]
|
|
15
|
+
__version__ = "1.1.0"
|
pitopt/__main__.py
ADDED
pitopt/cli.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
# Copyright (c) 2026 Orebit (Ghozian Islam Karami)
|
|
3
|
+
"""Command-line entry point: pit optimisation driven by a YAML project file."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
import uuid
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from .config import ProjectConfig
|
|
12
|
+
from .core.economics import marginal_cutoff_grades, product_margin
|
|
13
|
+
from .core.precedence import auto_bench_levels, effective_slope
|
|
14
|
+
from .io.console import format_report, summarise_pit
|
|
15
|
+
from .pipeline import run
|
|
16
|
+
from .ui.staging import discard, promote, staging_dir
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _cmd_run(args: argparse.Namespace) -> int:
|
|
20
|
+
cfg = ProjectConfig.from_yaml(args.config)
|
|
21
|
+
if args.outdir:
|
|
22
|
+
cfg.output.directory = str(Path(args.outdir).resolve())
|
|
23
|
+
|
|
24
|
+
final = Path(cfg.output.directory).resolve()
|
|
25
|
+
stage = staging_dir(final, uuid.uuid4().hex[:10])
|
|
26
|
+
directory = str(final)
|
|
27
|
+
try:
|
|
28
|
+
cfg.output.directory = str(stage)
|
|
29
|
+
result = run(cfg, verbose=not args.quiet)
|
|
30
|
+
promote(stage, final, cfg.name, directory)
|
|
31
|
+
result.outputs = {label: str(final / Path(path).name) for label, path in result.outputs.items()}
|
|
32
|
+
finally:
|
|
33
|
+
discard(stage)
|
|
34
|
+
cfg.output.directory = directory
|
|
35
|
+
|
|
36
|
+
print()
|
|
37
|
+
print(format_report(result.report, cfg.economics))
|
|
38
|
+
print()
|
|
39
|
+
print(summarise_pit(result.report, result.depth, cfg.economics))
|
|
40
|
+
print()
|
|
41
|
+
print("Outputs:")
|
|
42
|
+
for label, path in result.outputs.items():
|
|
43
|
+
print(f" {label:<20} {path}")
|
|
44
|
+
return 0
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _cmd_validate(args: argparse.Namespace) -> int:
|
|
48
|
+
cfg = ProjectConfig.from_yaml(args.config)
|
|
49
|
+
|
|
50
|
+
problems = []
|
|
51
|
+
if not Path(cfg.block_model.path).exists():
|
|
52
|
+
problems.append(f"block model not found: {cfg.block_model.path}")
|
|
53
|
+
if cfg.surface.path and not Path(cfg.surface.path).exists():
|
|
54
|
+
problems.append(f"surface not found: {cfg.surface.path}")
|
|
55
|
+
|
|
56
|
+
econ = cfg.economics
|
|
57
|
+
print(f"Project : {cfg.name}")
|
|
58
|
+
print(f"Block model : {cfg.block_model.path}")
|
|
59
|
+
print(f"Surface : {cfg.surface.path or '(none — full model treated as rock)'}")
|
|
60
|
+
print(f"Block size : {cfg.block_model.dx} x {cfg.block_model.dy} x {cfg.block_model.dz}")
|
|
61
|
+
bm = cfg.block_model
|
|
62
|
+
levels = cfg.slope.max_bench_levels or auto_bench_levels(cfg.slope.overall_angle_deg, min(bm.dx, bm.dy), bm.dz)
|
|
63
|
+
achieved = effective_slope(cfg.slope.overall_angle_deg, min(bm.dx, bm.dy), bm.dz, levels)
|
|
64
|
+
print(
|
|
65
|
+
f"Slope : {cfg.slope.overall_angle_deg} deg design, template {levels} bench levels "
|
|
66
|
+
f"({'auto' if cfg.slope.max_bench_levels is None else 'fixed'})"
|
|
67
|
+
)
|
|
68
|
+
print(f" achieved : {achieved['axis_deg']:.1f} deg along grid axes, {achieved['diagonal_deg']:.1f} deg on diagonals")
|
|
69
|
+
if achieved["diagonal_deg"] > cfg.slope.overall_angle_deg + 5:
|
|
70
|
+
problems.append(
|
|
71
|
+
f"diagonal walls reach {achieved['diagonal_deg']:.1f} deg against a {cfg.slope.overall_angle_deg} deg design — "
|
|
72
|
+
"raise slope.max_bench_levels or leave it unset"
|
|
73
|
+
)
|
|
74
|
+
print(f"Revenue factors: {cfg.shells.revenue_factors}")
|
|
75
|
+
print(f"Grade basis : {econ.grade_basis}")
|
|
76
|
+
print("Products :")
|
|
77
|
+
cutoffs = marginal_cutoff_grades(econ, 1.0, cfg.block_model.density)
|
|
78
|
+
for product in econ.products:
|
|
79
|
+
margin = product_margin(econ, product, 1.0)
|
|
80
|
+
print(
|
|
81
|
+
f" {product.name:<12} price {product.price:>9,.2f} recovery {product.plant_recovery:.3f}"
|
|
82
|
+
f" net margin/t {margin:>9,.2f} cutoff {cutoffs[product.name]:.4f}"
|
|
83
|
+
)
|
|
84
|
+
feed_cost = econ.processing_cost_per_volume + cfg.block_model.density * econ.processing_cost_per_tonne
|
|
85
|
+
if feed_cost <= 0:
|
|
86
|
+
print(" (no ore-level processing cost, so cutoff is zero — the pit limit is set")
|
|
87
|
+
print(" by whether revenue covers mining and rehabilitation, not by grade)")
|
|
88
|
+
|
|
89
|
+
if problems:
|
|
90
|
+
print("\nProblems:")
|
|
91
|
+
for problem in problems:
|
|
92
|
+
print(f" - {problem}")
|
|
93
|
+
return 1
|
|
94
|
+
print("\nConfig OK.")
|
|
95
|
+
return 0
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _cmd_reblock(args: argparse.Namespace) -> int:
|
|
99
|
+
from .core.reblock import ReblockSpec, reblock, write_outputs
|
|
100
|
+
|
|
101
|
+
spec = ReblockSpec(
|
|
102
|
+
source=args.source,
|
|
103
|
+
x=args.x, y=args.y, z=args.z,
|
|
104
|
+
size_x=args.size_cols[0] if args.size_cols else None,
|
|
105
|
+
size_y=args.size_cols[1] if args.size_cols else None,
|
|
106
|
+
size_z=args.size_cols[2] if args.size_cols else None,
|
|
107
|
+
parent=tuple(args.parent) if args.parent else None,
|
|
108
|
+
grades=args.grades or [],
|
|
109
|
+
categories=args.categories or [],
|
|
110
|
+
density=args.density,
|
|
111
|
+
target=tuple(args.size),
|
|
112
|
+
normalise=dict(args.normalise or []),
|
|
113
|
+
)
|
|
114
|
+
blocks, summary = reblock(spec)
|
|
115
|
+
written = write_outputs(blocks, spec, args.out, args.name, surface=not args.no_topo)
|
|
116
|
+
|
|
117
|
+
print(f"Source : {args.source}")
|
|
118
|
+
print(f"Parent block : {' x '.join(f'{v:g}' for v in summary['parent_size'].values())} m")
|
|
119
|
+
print("Grid origin : " + " ".join(f"{k.upper()} {v:,.3f}" for k, v in summary["origin"].items()))
|
|
120
|
+
print(f"Reblocked to : {summary['blocks']:,} blocks of {' x '.join(f'{v:g}' for v in spec.target)} m")
|
|
121
|
+
print(f"Volume source : {summary['source_volume']:,.1f} m3")
|
|
122
|
+
print(f"Volume reblocked : {summary['output_volume']:,.1f} m3 "
|
|
123
|
+
f"(difference {summary['output_volume'] - summary['source_volume']:+,.3f})")
|
|
124
|
+
print(f"Grades weighted by: {summary['grade_weighting']}")
|
|
125
|
+
table = summary["source_volume_by_category"]
|
|
126
|
+
if table is not None:
|
|
127
|
+
print("\nSource volume by " + " x ".join(spec.categories) + " (reconcile against the published resource):")
|
|
128
|
+
print(table.to_frame("volume_m3").to_string(float_format=lambda v: f"{v:,.1f}"))
|
|
129
|
+
for label, path in written.items():
|
|
130
|
+
print(f"{label:<18}: {path}")
|
|
131
|
+
|
|
132
|
+
import json
|
|
133
|
+
|
|
134
|
+
record = {
|
|
135
|
+
"source": Path(args.source).name,
|
|
136
|
+
"parent_size": summary["parent_size"],
|
|
137
|
+
"target": list(spec.target),
|
|
138
|
+
"origin": summary["origin"],
|
|
139
|
+
"blocks": summary["blocks"],
|
|
140
|
+
"source_volume": summary["source_volume"],
|
|
141
|
+
"output_volume": summary["output_volume"],
|
|
142
|
+
"grade_weighting": summary["grade_weighting"],
|
|
143
|
+
"categories": list(spec.categories),
|
|
144
|
+
"source_volume_by_category": (
|
|
145
|
+
table.reset_index().rename(columns={"volume": "volume_m3"}).to_dict("records") if table is not None else []
|
|
146
|
+
),
|
|
147
|
+
"partial_fill_below_half": float((blocks["FILL"] < 0.5).mean()),
|
|
148
|
+
}
|
|
149
|
+
reblock_json = Path(args.out) / f"{args.name}_reblock.json"
|
|
150
|
+
reblock_json.write_text(json.dumps(record, indent=2))
|
|
151
|
+
print(f"{'reblock summary':<18}: {reblock_json}")
|
|
152
|
+
return 0
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def main(argv: list[str] | None = None) -> int:
|
|
156
|
+
parser = argparse.ArgumentParser(prog="pitopt", description="Open-pit ultimate pit limit optimisation (SciPy Dinic max-flow)")
|
|
157
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
158
|
+
|
|
159
|
+
run_parser = sub.add_parser("run", help="solve the pit and write DXF/CSV outputs")
|
|
160
|
+
run_parser.add_argument("--config", required=True, help="project YAML file")
|
|
161
|
+
run_parser.add_argument("--outdir", help="override the output directory from the config")
|
|
162
|
+
run_parser.add_argument("--quiet", action="store_true", help="suppress progress output")
|
|
163
|
+
run_parser.set_defaults(func=_cmd_run)
|
|
164
|
+
|
|
165
|
+
validate_parser = sub.add_parser("validate", help="check the config and report derived parameters")
|
|
166
|
+
validate_parser.add_argument("--config", required=True, help="project YAML file")
|
|
167
|
+
validate_parser.set_defaults(func=_cmd_validate)
|
|
168
|
+
|
|
169
|
+
ui_parser = sub.add_parser("ui", help="start the local web UI")
|
|
170
|
+
ui_parser.add_argument("--root", default=".", help="project root containing projects/")
|
|
171
|
+
ui_parser.add_argument("--port", type=int, default=8765)
|
|
172
|
+
ui_parser.add_argument("--no-browser", action="store_true")
|
|
173
|
+
ui_parser.add_argument("--public-host", default=None, help="hostname(s) a reverse proxy forwards as Host, e.g. pitopt.orebit.id")
|
|
174
|
+
ui_parser.add_argument("--demo", action="store_true", help="read-only public showcase: block every mutating request except the bench-design screens")
|
|
175
|
+
ui_parser.set_defaults(func=lambda a: (__import__("pitopt.ui.server", fromlist=["serve"]).serve(a.root, a.port, not a.no_browser, a.public_host, a.demo), 0)[1])
|
|
176
|
+
|
|
177
|
+
reblock_parser = sub.add_parser(
|
|
178
|
+
"reblock", help="regularise a sub-celled / finely estimated block model (CSV or .DAT) to mining blocks"
|
|
179
|
+
)
|
|
180
|
+
reblock_parser.add_argument("source", help="block model: CSV, or self-describing fixed-width .DAT")
|
|
181
|
+
reblock_parser.add_argument("--out", required=True, help="output directory")
|
|
182
|
+
reblock_parser.add_argument("--name", default="model", help="output file prefix")
|
|
183
|
+
reblock_parser.add_argument("--size", nargs=3, type=float, required=True, metavar=("DX", "DY", "DZ"), help="target block size")
|
|
184
|
+
reblock_parser.add_argument("--x", default="X")
|
|
185
|
+
reblock_parser.add_argument("--y", default="Y")
|
|
186
|
+
reblock_parser.add_argument("--z", default="Z")
|
|
187
|
+
reblock_parser.add_argument("--size-cols", nargs=3, metavar=("SX", "SY", "SZ"), help="per-block size columns")
|
|
188
|
+
reblock_parser.add_argument("--parent", nargs=3, type=float, metavar=("PX", "PY", "PZ"), help="fixed source block size")
|
|
189
|
+
reblock_parser.add_argument("--grades", nargs="*", help="grade columns to average")
|
|
190
|
+
reblock_parser.add_argument("--categories", nargs="*", help="categorical columns (domain, class)")
|
|
191
|
+
reblock_parser.add_argument("--density", help="density column; grades are then mass-weighted")
|
|
192
|
+
reblock_parser.add_argument(
|
|
193
|
+
"--normalise", nargs=2, action="append", metavar=("COLUMN", "REGEX"),
|
|
194
|
+
help="strip a pattern from a categorical column first, e.g. --normalise CLASS '\\d+$'",
|
|
195
|
+
)
|
|
196
|
+
reblock_parser.add_argument("--no-topo", action="store_true", help="skip the top-of-model surface DXF")
|
|
197
|
+
reblock_parser.set_defaults(func=_cmd_reblock)
|
|
198
|
+
|
|
199
|
+
mcp_parser = sub.add_parser("mcp", help="start the Model Context Protocol (MCP) stdio server")
|
|
200
|
+
mcp_parser.set_defaults(func=lambda _a: __import__("pitopt.mcp_server", fromlist=["main"]).main())
|
|
201
|
+
|
|
202
|
+
args = parser.parse_args(argv)
|
|
203
|
+
return args.func(args)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if __name__ == "__main__":
|
|
207
|
+
sys.exit(main())
|