Skip to content

feat: add factory simulation demo with maintenance optimisation#215

Merged
toby-coleman merged 8 commits into
mainfrom
copilot/add-factory-simulation-demo
Mar 3, 2026
Merged

feat: add factory simulation demo with maintenance optimisation#215
toby-coleman merged 8 commits into
mainfrom
copilot/add-factory-simulation-demo

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 28, 2026

Summary

New demo simulating a factory with 5 machines over 365 days. Each machine has sigmoid-based breakdown probability, configurable proactive maintenance intervals, and fixed repair downtime. Includes a tuner config to optimise maintenance schedules for maximum output, a Jupyter notebook for interactive exploration, and a mermaid process diagram.

Changes

  • factory_simulation.py defines the simulation components and machine configurations:
    • Iterator component drives the simulation for a configurable number of days
    • Machine component (5 instances with distinct parameters):
      • $10k/day output when running
      • Breakdown probability: 1 / (1 + exp(-k * (days_since_maintenance - midpoint))) — different k and midpoint per machine
      • 5-day downtime on breakdown, 1-day downtime for scheduled maintenance
      • Seeded RNG for reproducibility
    • Factory component aggregates daily output across all machines into cumulative total
    • MACHINE_CONFIGS list defines the 5 machine reliability profiles
  • factory-simulation.yaml wires the process and defines a Tuner config optimising each machine's maintenance_interval (range 5–60 days) to maximise total_value
  • factory-simulation.ipynb Jupyter notebook that:
    • Imports components from factory_simulation.py
    • Builds the process and connects components
    • Includes a mermaid diagram (static image + dynamic MermaidDiagram.from_process() generation)
    • Runs the simulation with results and efficiency metrics
    • Builds a ProcessSpec programmatically and configures a Tuner with IntParameterSpec parameters for optimisation
    • References the CLI alternative (plugboard process tune factory-simulation.yaml)
  • mkdocs.yaml updated to include the notebook under Demos > Fundamentals > Factory simulation

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 28, 2026 20:38
Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com>
Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com>
Copilot AI changed the title [WIP] Add factory simulation demo with machine management feat: add factory simulation demo with maintenance optimisation Feb 28, 2026
Copy link
Copy Markdown
Contributor

@toby-coleman toby-coleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Include a Jupyter notebook as well (it could import Components from factory_simulation.py). It should be in a similar format to the other demo notebooks, and be referenced in the mkdocs yaml to publish as documentation. Include a mermaid diagram of the process that you built.

Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 28, 2026

@copilot Include a Jupyter notebook as well (it could import Components from factory_simulation.py). It should be in a similar format to the other demo notebooks, and be referenced in the mkdocs yaml...

Added in 52ac46a. The notebook factory-simulation.ipynb imports components from factory_simulation.py, includes a mermaid process diagram (both a static mermaid.ink image and a dynamic MermaidDiagram.from_process() cell), and is referenced in mkdocs.yaml under Demos > Fundamentals > Factory simulation. Verified the mkdocs build succeeds with the new entry.

@toby-coleman
Copy link
Copy Markdown
Contributor

@copilot move the optimisation code from the factory_simulation.py to the notebook.

Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot move the optimisation code from the factory_simulation.py to the notebook.

Done in 6f5bbe3. Moved build_process_spec(), run_optimisation(), and the __main__ block from factory_simulation.py to the notebook as executable code cells. The .py file now only contains component definitions and MACHINE_CONFIGS, matching the production line demo pattern.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Benchmark comparison for 829f9812 (base) vs ab186856 (PR)


------------------------------------------------------------------------------------------------------------------ benchmark: 2 tests -----------------------------------------------------------------------------------------------------------------
Name (time in ms)                                                                         Min                 Max                Mean            StdDev              Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_process_run (main/.benchmarks/Linux-CPython-3.12-64bit/0001_base)     458.0421 (1.0)      472.2941 (1.01)     464.4814 (1.00)     5.5682 (1.70)     465.1895 (1.00)     8.1677 (1.53)          2;0  2.1529 (1.00)          5           1
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         459.6762 (1.00)     467.6987 (1.0)      463.5608 (1.0)      3.2707 (1.0)      464.1391 (1.0)      5.3423 (1.0)           2;0  2.1572 (1.0)           5           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Benchmark comparison for 829f9812 (base) vs 2f3aba97 (PR)


------------------------------------------------------------------------------------------------------------------ benchmark: 2 tests ------------------------------------------------------------------------------------------------------------------
Name (time in ms)                                                                         Min                 Max                Mean            StdDev              Median                IQR            Outliers     OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         446.3249 (1.0)      460.7330 (1.0)      453.0593 (1.0)      6.7829 (1.24)     451.6820 (1.0)      12.9576 (1.60)          1;0  2.2072 (1.0)           5           1
test_benchmark_process_run (main/.benchmarks/Linux-CPython-3.12-64bit/0001_base)     452.3395 (1.01)     466.5269 (1.01)     459.4281 (1.01)     5.4706 (1.0)      458.8302 (1.02)      8.1135 (1.0)           2;0  2.1766 (0.99)          5           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

@toby-coleman toby-coleman marked this pull request as ready for review March 3, 2026 21:39
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Benchmark comparison for c698160d (base) vs 246e18c1 (PR)


------------------------------------------------------------------------------------------------------------------- benchmark: 2 tests ------------------------------------------------------------------------------------------------------------------
Name (time in ms)                                                                         Min                 Max                Mean             StdDev              Median                IQR            Outliers     OPS            Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         456.3567 (1.0)      486.3324 (1.03)     466.6191 (1.00)     11.6433 (2.71)     462.3593 (1.0)      11.8307 (1.53)          1;0  2.1431 (1.00)          5           1
test_benchmark_process_run (main/.benchmarks/Linux-CPython-3.12-64bit/0001_base)     460.9011 (1.01)     470.2180 (1.0)      466.3059 (1.0)       4.2935 (1.0)      468.1247 (1.01)      7.7230 (1.0)           1;0  2.1445 (1.0)           5           1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

@toby-coleman toby-coleman merged commit fbc55e7 into main Mar 3, 2026
19 checks passed
@toby-coleman toby-coleman deleted the copilot/add-factory-simulation-demo branch March 3, 2026 21:46
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants