Simulation

Simulation

Bases: BaseModel

Declarative MEEP FDTD simulation container.

Assigns typed physics objects, then calls write_config() to produce the JSON + GDS + runner consumed by the cloud engine.

Example::

from gsim import meep

sim = meep.Simulation()
sim.geometry.component = ybranch
sim.geometry.stack = stack
sim.materials = {"si": 3.47, "sio2": 1.44}
sim.source.port = "o1"
sim.monitors = ["o1", "o2"]
sim.solver.stopping = "dft_decay"
sim.solver.max_time = 200
result = sim.run()  # creates sim-data-{job_name}/ in CWD

Methods:

  • validate_config

    Validate the simulation configuration.

  • write_config

    Serialize simulation config to output directory.

  • plot_2d

    Plot 2D cross-sections of the geometry.

  • plot_3d

    Plot 3D visualization of the geometry.

  • run

    Run MEEP simulation on the cloud.

  • start

    Start cloud execution for this sim's uploaded job.

  • upload

    Write config and upload to the cloud. Does NOT start execution.

  • get_status

    Get the current status of this sim's cloud job.

  • wait_for_results

    Wait for this sim's cloud job, download and parse results.

Attributes:

geometry class-attribute instance-attribute

geometry: Geometry = Field(default_factory=Geometry)

source class-attribute instance-attribute

source: ModeSource = Field(default_factory=ModeSource)

domain class-attribute instance-attribute

domain: Domain = Field(default_factory=Domain)

solver class-attribute instance-attribute

solver: FDTD = Field(default_factory=FDTD)

validate_config

validate_config() -> Any

Validate the simulation configuration.

Returns:

  • Any

    ValidationResult with errors/warnings.

write_config

write_config(output_dir: str | Path) -> Path

Serialize simulation config to output directory.

Thin wrapper around :meth:build_config — writes GDS, JSON, and the runner script.

Parameters:

  • output_dir (str | Path) –

    Directory to write layout.gds, sim_config.json, run_meep.py.

Returns:

  • Path

    Path to the output directory.

Raises:

plot_2d

plot_2d(**kwargs: Any) -> Any

Plot 2D cross-sections of the geometry.

Uses :meth:build_config so the plot shows exactly what meep processes — including extended ports and PML boundaries.

Accepts the same keyword arguments as :func:gsim.meep.viz.plot_2d.

plot_3d

plot_3d(**kwargs: Any) -> Any

Plot 3D visualization of the geometry.

Uses :meth:build_config so the plot shows exactly what meep processes — including extended ports.

Accepts the same keyword arguments as :func:gsim.meep.viz.plot_3d.

run

run(
    parent_dir: str | Path | None = None,
    *,
    verbose: Literal["quiet", "status", "full"] = "status",
    wait: bool = True,
) -> Any

Run MEEP simulation on the cloud.

Parameters:

  • parent_dir (str | Path | None, default: None ) –

    Where to create the sim directory. Defaults to the current working directory.

  • verbose (Literal['quiet', 'status', 'full'], default: 'status' ) –

    "quiet" no output, "status" status line, "full" stream solver logs.

  • wait (bool, default: True ) –

    If True (default), block until results are ready. If False, upload + start and return the job_id.

Returns:

  • Any

    SParameterResult when wait=True, or job_id string

  • Any

    when wait=False.

start

start(*, verbose: bool = True) -> None

Start cloud execution for this sim's uploaded job.

Raises:

  • ValueError

    If :meth:upload has not been called.

upload

upload(*, verbose: bool = True) -> str

Write config and upload to the cloud. Does NOT start execution.

Parameters:

  • verbose (bool, default: True ) –

    Print progress messages.

Returns:

  • str

    job_id string for use with :meth:start, :meth:get_status,

  • or ( str ) –

    func:gsim.wait_for_results.

get_status

get_status() -> str

Get the current status of this sim's cloud job.

Returns:

  • str

    Status string ("created", "queued", "running",

  • str

    "completed", "failed").

Raises:

  • ValueError

    If no job has been submitted yet.

wait_for_results

wait_for_results(
    *,
    verbose: Literal["quiet", "status", "full"] = "status",
    parent_dir: str | Path | None = None,
) -> Any

Wait for this sim's cloud job, download and parse results.

Parameters:

  • verbose (Literal['quiet', 'status', 'full'], default: 'status' ) –

    "quiet" no output, "status" status line, "full" stream solver logs.

  • parent_dir (str | Path | None, default: None ) –

    Where to create the sim-data directory.

Returns:

  • Any

    Parsed result (typically SParameterResult).

Raises:

  • ValueError

    If no job has been submitted yet.

Configuration

Geometry

Bases: BaseModel

Physical layout: component + layer stack + optional z-crop.

Domain

Bases: BaseModel

Computational domain sizing: PML + margins + symmetries.

ModeSource

Bases: BaseModel

Mode source excitation and spectral measurement window.

Results

SParameterResult

Bases: BaseModel

S-parameter results from MEEP simulation.

Parses CSV output from the cloud runner and provides visualization via matplotlib.

Methods:

  • from_csv

    Parse S-parameter results from CSV file.

  • from_directory

    Load from directory — handles preview-only with no CSV.

  • plot

    Plot S-parameters vs wavelength.

  • show_animation

    Display field animation MP4 in Jupyter.

  • show_diagnostics

    Display diagnostic images in Jupyter.

from_csv classmethod

from_csv(path: str | Path) -> SParameterResult

Parse S-parameter results from CSV file.

Expected CSV format

wavelength,S11_mag,S11_phase,S21_mag,S21_phase,... 1.5, 0.1, -30.0, 0.9, 45.0, ...

Automatically loads meep_debug.json from the same directory if it exists, populating the debug_info field.

Parameters:

  • path (str | Path) –

    Path to CSV file

Returns:

from_directory classmethod

from_directory(directory: str | Path) -> SParameterResult

Load from directory — handles preview-only with no CSV.

If s_parameters.csv exists, delegates to from_csv(). Otherwise loads only debug info and diagnostic images (preview mode).

Parameters:

  • directory (str | Path) –

    Path to results directory

Returns:

plot

plot(db: bool = True, **kwargs: Any) -> Any

Plot S-parameters vs wavelength.

Parameters:

  • db (bool, default: True ) –

    If True, plot in dB scale

  • **kwargs (Any, default: {} ) –

    Passed to matplotlib plot()

Returns:

  • Any

    matplotlib Figure

show_animation

show_animation() -> None

Display field animation MP4 in Jupyter.

show_diagnostics

show_diagnostics() -> None

Display diagnostic images in Jupyter.