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:
write_config
¶
Serialize simulation config to output directory.
Thin wrapper around :meth:build_config — writes GDS, JSON, and
the runner script.
Parameters:
Returns:
-
Path–Path to the output directory.
Raises:
-
ValueError–If config is invalid.
plot_2d
¶
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 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. IfFalse, upload + start and return thejob_id.
Returns:
start
¶
start(*, verbose: bool = True) -> None
Start cloud execution for this sim's uploaded job.
Raises:
-
ValueError–If :meth:
uploadhas not been called.
upload
¶
get_status
¶
get_status() -> str
Get the current status of this sim's cloud job.
Returns:
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:
Returns:
-
SParameterResult–SParameterResult instance
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:
Returns:
-
SParameterResult–SParameterResult instance