Skip to content

docs: Crusher circuit example#229

Draft
toby-coleman wants to merge 2 commits intomainfrom
chore/crusher-circuit-example
Draft

docs: Crusher circuit example#229
toby-coleman wants to merge 2 commits intomainfrom
chore/crusher-circuit-example

Conversation

@toby-coleman
Copy link
Contributor

Summary

Adds a simple model of a crusher circuit using a population balance model (PBM) approach. Includes recirculation to showcase Plugboard feedback loops.

Changes

  • Notebook for a crusher circuit.
  • Optimisation example [WIP]
  • Updated LLM prompts, including researcher agent for use with NotebookLM MCP server.

@github-actions
Copy link

Benchmark comparison for 64adfa9a (base) vs 6e910476 (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)     447.7165 (1.0)      457.0178 (1.0)      452.2852 (1.0)      3.9510 (1.0)      451.2083 (1.0)      6.7746 (2.13)          2;0  2.2110 (1.0)           5           1
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         462.4066 (1.03)     471.8064 (1.03)     464.7280 (1.03)     3.9888 (1.01)     463.1687 (1.03)     3.1747 (1.0)           1;1  2.1518 (0.97)          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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive example of a mineral processing crusher circuit simulation within the Plugboard framework. It demonstrates dynamic modeling using the Population Balance Model, incorporates a recirculation loop with transport delays, and includes parameter optimization capabilities. Concurrently, it updates the AI agent configurations to better support the development and documentation of such complex examples, enhancing the framework's utility for technical users.

Highlights

  • New Example: Crusher Circuit Simulation: Implemented a dynamic crusher circuit simulation using the Population Balance Model (PBM) approach, showcasing complex physical process modeling within Plugboard.
  • Recirculation Loop Demonstration: Demonstrated Plugboard's feedback loop capabilities with a recirculation circuit that includes a transport delay, illustrating realistic transient dynamics.
  • AI Agent Enhancements: Introduced new AI agent definitions for 'examples' and 'researcher' roles, and updated existing 'docs' and 'lint' agent configurations to specify LLM models, improving automated development support.
Changelog
  • .github/agents/docs.agent.md
    • Added a 'model' field to the agent configuration.
  • .github/agents/examples.agent.md
    • Added a new agent definition for developing Plugboard examples and tutorials.
  • .github/agents/lint.agent.md
    • Added a 'model' field to the agent configuration.
  • .github/agents/researcher.agent.md
    • Added a new agent definition for researching topics related to Plugboard.
  • examples/AGENTS.md
    • Refactored the document to focus on general Plugboard model creation guidelines.
    • Removed specific example categories and Jupyter Notebook guidelines.
  • examples/demos/physics-models/002-crusher-circuit/.gitignore
    • Added a new gitignore file to exclude CSV output.
  • examples/demos/physics-models/002-crusher-circuit/_test_dynamics.py
    • Added a new Python script to test the crusher circuit simulation.
  • examples/demos/physics-models/002-crusher-circuit/crusher_circuit.ipynb
    • Added a new Jupyter Notebook demonstrating the crusher circuit simulation, including PBM background, component definitions, simulation run, visualization, and parameter optimization.
  • examples/demos/physics-models/002-crusher-circuit/crusher_circuit.py
    • Added a new Python module containing the PSD data model and Plugboard components (FeedSource, Crusher, Screen, Conveyor, ProductCollector) for the crusher circuit.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an excellent, comprehensive example of a crusher circuit simulation, which effectively showcases Plugboard's capabilities for physics-based modeling. The addition of the Jupyter notebook, Python components, and a test script is well-executed. The PR also includes valuable refactoring and additions to the AI agent definitions. I've identified a few potential runtime issues in the new Python code related to error handling and defensive programming. My specific comments provide suggestions to enhance the robustness of the simulation code. These changes should be applied to both the .py module and the corresponding Jupyter notebook. Overall, this is a strong contribution.

Comment on lines +457 to +468
" total_mass = feed_mass + recirc_mass\n",
" w_f = feed_mass / total_mass\n",
" w_r = recirc_mass / total_mass\n",
" combined = [\n",
" w_f * f + w_r * r\n",
" for f, r in zip(feed.mass_fractions, recirc_psd.mass_fractions)\n",
" ]\n",
" feed = PSD(\n",
" size_classes=feed.size_classes,\n",
" mass_fractions=combined,\n",
" mass_tonnes=total_mass,\n",
" )\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There's a potential ZeroDivisionError here if total_mass is 0. This can occur if both feed_mass and recirc_mass are zero. It's important to add a guard to handle this case to prevent the simulation from crashing.

            total_mass = feed_mass + recirc_mass
            if total_mass > 0:
                w_f = feed_mass / total_mass
                w_r = recirc_mass / total_mass
                combined = [
                    w_f * f + w_r * r
                    for f, r in zip(feed.mass_fractions, recirc_psd.mass_fractions)
                ]
                feed = PSD(
                    size_classes=feed.size_classes,
                    mass_fractions=combined,
                    mass_tonnes=total_mass,
                )

Comment on lines +472 to +475
" if self._breakage is None:\n",
" raise RuntimeError(\"Breakage matrix not initialised\")\n",
" for _ in range(self._n_stages):\n",
" result = apply_crusher(result, self._selection, self._breakage)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

high

self._selection is not checked for None before being passed to apply_crusher. Since apply_crusher expects a list[float], this could lead to a TypeError if the matrices have not been initialized. It's safer to check for both self._selection and self._breakage before proceeding.

        if self._selection is None or self._breakage is None:
            raise RuntimeError("Selection or breakage matrix not initialised")
        for _ in range(self._n_stages):
            result = apply_crusher(result, self._selection, self._breakage)

Comment on lines +333 to +343
total_mass = feed_mass + recirc_mass
w_f = feed_mass / total_mass
w_r = recirc_mass / total_mass
combined = [
w_f * f + w_r * r for f, r in zip(feed.mass_fractions, recirc_psd.mass_fractions)
]
feed = PSD(
size_classes=feed.size_classes,
mass_fractions=combined,
mass_tonnes=total_mass,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There's a potential ZeroDivisionError here if total_mass is 0. This can occur if both feed_mass and recirc_mass are zero. You should add a guard to handle this case to prevent the simulation from crashing.

Suggested change
total_mass = feed_mass + recirc_mass
w_f = feed_mass / total_mass
w_r = recirc_mass / total_mass
combined = [
w_f * f + w_r * r for f, r in zip(feed.mass_fractions, recirc_psd.mass_fractions)
]
feed = PSD(
size_classes=feed.size_classes,
mass_fractions=combined,
mass_tonnes=total_mass,
)
total_mass = feed_mass + recirc_mass
if total_mass > 0:
w_f = feed_mass / total_mass
w_r = recirc_mass / total_mass
combined = [
w_f * f + w_r * r for f, r in zip(feed.mass_fractions, recirc_psd.mass_fractions)
]
feed = PSD(
size_classes=feed.size_classes,
mass_fractions=combined,
mass_tonnes=total_mass,
)

Comment on lines +346 to +350
if self._breakage is None:
msg = "Breakage matrix not initialised"
raise RuntimeError(msg)
for _ in range(self._n_stages):
result = apply_crusher(result, self._selection, self._breakage)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

self._selection is not checked for None before being passed to apply_crusher, which could lead to a TypeError if the matrices have not been initialized. It's safer to check for both self._selection and self._breakage before using them.

Suggested change
if self._breakage is None:
msg = "Breakage matrix not initialised"
raise RuntimeError(msg)
for _ in range(self._n_stages):
result = apply_crusher(result, self._selection, self._breakage)
if self._selection is None or self._breakage is None:
msg = "Selection or breakage matrix not initialised"
raise RuntimeError(msg)
for _ in range(self._n_stages):
result = apply_crusher(result, self._selection, self._breakage)


## Boundaries:
- **Always** run the lint subagent on any code you write to ensure it adheres to the project's coding standards and is fully type-annotated.
- **Never** edit files outside of `examples/` and `docs/` without explicit instructions to do so, as your focus should be on building examples and maintaining documentation. No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Please add a newline at the end of the file. It's a common convention that helps prevent issues with some command-line tools and version control systems.

## Boundaries:
- **Always** provide clear and concise summaries of the information you gather.
- Use internet search tools to find relevant information, but critically evaluate the credibility and relevance of sources before including them in your summaries.
- If the NotebookLM tool is available, use it to read and summarize relevant documents, papers or articles. Ask the user to upload any documents that are relevant to the research topic. No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Please add a newline at the end of the file. It's a common convention that helps prevent issues with some command-line tools and version control systems.

" self.psd_history: list[dict[str, _t.Any]] = []\n",
"\n",
" async def step(self) -> None:\n",
" psd = PSD(**self.product_psd)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

In some edge cases (e.g., during process startup or shutdown), self.product_psd could be None. This would cause PSD(**self.product_psd) to raise a TypeError. Adding a None check would make this component more robust.

        if self.product_psd is None:
            return
        psd = PSD(**self.product_psd)


async def step(self) -> None:
"""Record the product PSD and emit quality metrics."""
psd = PSD(**self.product_psd)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

self.product_psd could be None in some edge cases (e.g., during process startup or shutdown), which would cause PSD(**self.product_psd) to raise a TypeError. Adding a None check would make this component more robust.

Suggested change
psd = PSD(**self.product_psd)
if self.product_psd is None:
return
psd = PSD(**self.product_psd)

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.

1 participant