pycsamt.agents.inversion_backend#

pycsamt.agents.inversion_backend#

InversionBackendAgent — Drive the pycsamt.inversion physics-based inversion backends from within the agent system.

Supports all backends registered in pycsamt.inversion:

  • builtin — pure-Python FD MT/TDEM inversion (no extra dependencies)

  • simpeg — SimPEG MT/3D natural-source inversion (optional)

  • pygimli — pyGIMLi 1-D MT/TDEM inversion (optional)

  • occam2d — Occam2D data-file runner (requires Occam binary)

  • modem — ModEM3D data-file runner (requires ModEM binary)

The agent wraps run_inversion() and InversionConfig, converts the raw InversionResult into a standard AgentResult, and plots the final resistivity section using the PYCSAMT API.

Classes

InversionBackendAgent(*[, api_key, model, ...])

Drive pycsamt.inversion physics-based backends.

class pycsamt.agents.inversion_backend.InversionBackendAgent(*, api_key=None, model=None, llm_provider='claude', backend='builtin', dimension='1d', method='mt', n_layers=5, max_iter=80, regularization='smooth', error_floor=0.05)[source]#

Bases: BaseAgent

Drive pycsamt.inversion physics-based backends.

Parameters:
  • api_key (str)

  • model (str)

  • llm_provider (str)

  • backend (str, optional overrides) – Inversion backend: 'builtin' (default), 'simpeg', 'pygimli', 'occam2d', 'modem'.

  • dimension (str, optional overrides) – '1d' (default), '2d', or '3d'.

  • method (str, optional overrides) – 'mt' (default), 'amt', 'csamt', or 'tdem'.

  • n_layers (int, optional overrides) – Number of depth layers for 1-D inversion (default 5).

  • max_iter (int, optional overrides) – Maximum inversion iterations (default 80).

  • regularization (optional overrides) – 'smooth' (default), 'damped', or 'blocky'.

  • error_floor (optional overrides) – Relative data error floor (default 0.05 = 5 %).

  • keys (Output data)

  • ----------

  • path (sites /)

  • backend

  • dimension

  • method

  • n_layers

  • max_iter

  • regularization

  • error_floor

  • backend_options (dict, optional — forwarded to InversionConfig)

  • output_dir (str, optional)

  • keys

  • ----------------

  • InversionResult (inversion_result)

  • float (rms)

  • int (n_iter)

  • (n_layers (log_rho_section ndarray)

  • n_stations)

  • None (station_names list[str] or)

  • str (dimension)

  • str

  • dict (figure_paths)

  • dict

SYSTEM_PROMPT: str = 'You are an expert in MT inversion and subsurface resistivity modelling.\nGiven an inversion result, write 4-5 sentences that:\n1. State the backend used, dimensionality, and convergence (RMS, n_iter).\n2. Describe the recovered resistivity model (range, dominant structures).\n3. Assess the fit quality and whether the RMS target was reached.\n4. Identify stations or depth ranges with elevated misfit.\n5. Recommend regularisation adjustments or mesh refinements for the next run.\nReply in plain scientific English.\n'#

Override in subclasses to give the LLM its domain expertise.

execute(input_data)[source]#

Run this agent on input_data and return an AgentResult.

Subclasses must implement this method. The contract:

  • Reset self._last_cost = 0.0 at the top.

  • Record wall-clock time with t0 = time.time().

  • Return AgentResult(elapsed_seconds=time.time()-t0, cost_estimate_usd=self._last_cost, ...).

Parameters:

input_data (dict[str, Any])

Return type:

AgentResult