Inspiration

Partial differential equations describe heat transfer, fluid flow, waves, diffusion, and many other physical systems. However, solving a PDE numerically requires more than generating code. A user must select a suitable numerical method, check stability constraints, compare alternatives, execute the solver safely, and determine whether the result is accurate.

I built AutoNumerics Agent to automate this workflow while keeping the reasoning and numerical evidence visible. Instead of returning one unverified script, the system generates several candidate solution plans, evaluates them, executes the strongest candidates, measures their errors, and recommends the best-performing method.

## What It Does

A user describes a PDE in natural language or selects one of five example problems. AutoNumerics then:

  1. Converts the description into a structured mathematical specification.
  2. Retrieves relevant numerical-method evidence from Elasticsearch.
  3. Generates between 1 and 10 candidate solution plans.
  4. Screens the plans for numerical stability and suitability.
  5. Generates executable Python solver code with Gemini.
  6. Runs between 1 and 10 selected plans in a bounded Cloud Run worker.
  7. Computes the available numerical errors.
  8. Selects the successful plan with the smallest comparable error.
  9. Plots the numerical solution and, when available, compares it with the analytic ground-truth solution.

For a known analytic solution (u_{\text{exact}}), the relative (L^2) error is

[ E_{L^2}

\frac{ \left|u_{\text{numerical}}-u_{\text{exact}}\right|_2 }{ \left|u{\text{exact}}\right|_2+\varepsilon }. ]

The maximum pointwise error is also computed:

[ E_{\max}

\max_i \left| u_{\text{numerical},i}-u_{\text{exact},i} \right|. ]

When no analytic solution exists, the system falls back to residual-based metrics.

## How I Built It

The interface is built with Streamlit and deployed on Google Cloud Run. The application uses:

  • Gemini on Vertex AI for PDE formulation, plan generation, and solver-code generation
  • Google ADK for the agent workflow
  • Elastic Cloud for retrieving numerical-method references
  • Cloud Run for hosting both the UI and the isolated execution worker
  • NumPy and SciPy for numerical computation
  • Matplotlib for solution visualization
  • FastAPI for the solver execution service

The project is split into two Cloud Run services:

  • The UI service manages user interaction and the agent workflow.
  • The worker service executes generated solver code with time and resource limits.

The worker returns error metrics and bounded plotting data. The UI compares successful executions using a consistent metric hierarchy and always plots the selected minimum-error plan.

## Challenges

### Safely executing generated code

Generated numerical code may contain errors, run for too long, or consume excessive resources. I separated code execution from the public UI and placed it inside a bounded Cloud Run worker with timeouts, limited concurrency, validation, and restricted result sizes.

### Comparing different numerical plans fairly

Some problems provide an analytic solution, while others do not. Comparing an exact-solution error from one plan with an unrelated residual metric from another would be misleading. I implemented a consistent selection hierarchy so plans are compared using the same available metric.

### Handling unpredictable model output

Generated code can arrive inside Markdown fences or explanatory text. I added extraction and validation logic to isolate executable Python code and verify the required solver interface before execution.

### Plotting different solver result formats

Solvers can return one-dimensional fields, two-dimensional fields, or time-dependent arrays with different axis arrangements. I built normalization and bounded sampling logic that identifies the final state, preserves coordinates, and produces consistent plotting payloads.

### Keeping the application deployable

The project originally depended on code outside the hackathon directory. I made the folder self- contained so it can be published as an independent GitHub repository and deployed without relying on parent-directory files.

## What I Learned

I learned that using an LLM for scientific computing requires more than prompting it to write code. A reliable system needs explicit validation, numerical metrics, safe execution boundaries, and evidence that users can inspect.

I also learned how to:

  • Build an agentic workflow with Google ADK
  • Use Gemini through Vertex AI
  • Deploy cooperating services on Cloud Run
  • Integrate Elastic retrieval into a numerical pipeline
  • Execute generated scientific code with practical safeguards
  • Compare numerical solutions using exact and residual-based errors
  • Design an interface that exposes reasoning without overwhelming users

Most importantly, I learned that AI works best here as part of a measurable engineering pipeline. The model proposes methods and implementations, but numerical validation determines which result is selected.

## Accomplishments

AutoNumerics now supports five demonstration PDEs, configurable plan generation and execution, stability screening, isolated solver execution, automatic error-based selection, numerical plotting, and analytic ground-truth comparison.

The result is not simply a code generator. It is an end-to-end numerical-method selection and validation system that turns a natural-language PDE description into an evaluated, executable, and visualized solution.

Built With

Share this project:

Updates