Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added run_batch functionality for the web mode solver, added parallel… #1654

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Properties `num_time_steps_adjoint` and `tmesh_adjoint` to `JaxSimulation` to estimate adjoint run time.
- Ability to add `path` to `updated_copy()` method to recursively update sub-components of a tidy3d model. For example `sim2 = sim.updated_copy(size=new_size, path="structures/0/geometry")` creates a recursively updated copy of `sim` where `sim.structures[0].geometry` is updated with `size=new_size`.
- Python 3.12 support. Python 3.8 deprecation. Updated dependencies.
- A batch of `ModeSolver` objects can be run concurrently using `tidy3d.plugins.mode.web.run_batch()`

### Changed
- IMPORTANT NOTE: differentiable fields in the `adjoint` plugin (`JaxBox.size`, `JaxBox.center`, `JaxPolySlab.vertices`) no longer store the derivative information after the object is initialized. For example, if using JaxPolySlab.vertices directly in an objective function, the vertices will have no effect on the gradient. Instead, this information is now stored in a field of the same name with `_jax` suffix, eg. `JaxPolySlab.vertices_jax`. For some applications, such as evaluating penalty values, please change to `radius_penalty.evaluate(polyslab.vertices_jax)` or use the vertices as generated by your parameterization functions (`make_vertices(params)`).
Expand Down
1 change: 1 addition & 0 deletions scripts/sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generates sample simulation json and h5 files in the tests/sims folder"""

from os.path import join
import sys

Expand Down
1 change: 1 addition & 0 deletions tests/_test_data/_test_datasets_no_vtk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests tidy3d/components/data/dataset.py"""

import pytest
import builtins
from ..test_data.test_datasets import test_triangular_dataset as _test_triangular_dataset
Expand Down
1 change: 1 addition & 0 deletions tests/_test_local/_test_web.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" tests converted webapi """

import os
from unittest import TestCase, mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/full_test_develop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
These scripts just test the CLI commands for the develop command, and verify that they run properly.
"""

import pytest
import os
from click.testing import CliRunner
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_IO.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests file export and loading."""

import os
import json

Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_apodization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests mode objects."""

import pytest
import pydantic.v1 as pydantic
import tidy3d as td
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the base model."""

import pytest
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests custom sources and mediums."""

import dill as pickle
from typing import Tuple

Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_field_projection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test near field to far field transformations."""

import numpy as np
import tidy3d as td
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests grid operations."""

import pytest
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_grid_spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests GridSpec."""

import pytest
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_medium.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests mediums."""

import numpy as np
import pytest
import pydantic.v1 as pydantic
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_meshgenerate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests generating meshes."""

import numpy as np
import warnings
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests mode objects."""

import pytest
import pydantic.v1 as pydantic
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests monitors."""

import pytest
import pydantic.v1 as pydantic
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_parameter_perturbation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests parameter perturbations."""

import numpy as np
import matplotlib.pyplot as plt
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_scene.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the scene and its validators."""

import pytest
import pydantic.v1 as pd
import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_sidewall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""test slanted polyslab can be correctly setup and visualized. """

import pytest
import numpy as np
import pydantic.v1 as pydantic
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the simulation and its validators."""

import pytest
import pydantic.v1 as pydantic
import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests sources."""

import pytest
import pydantic.v1 as pydantic
import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_time_modulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests space time modulation."""

import numpy as np
import pytest
from math import isclose
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests type definitions."""

import pytest
import pydantic.v1 as pydantic
from tidy3d.components.types import ArrayLike, Complex, constrained_array, Tuple
Expand Down
1 change: 1 addition & 0 deletions tests/test_components/test_viz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests visualization operations."""

import pytest
import matplotlib.pyplot as plt
import tidy3d as td
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/test_data_arrays.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests tidy3d/components/data/data_array.py"""

import pytest
import numpy as np
from typing import Tuple, List
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests tidy3d/components/data/dataset.py"""

import pytest
import numpy as np
import pydantic.v1 as pd
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/test_monitor_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests tidy3d/components/data/monitor_data.py"""

import numpy as np
import matplotlib.pyplot as plt
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/test_sim_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests SimulationData"""

import pytest
import numpy as np
import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions tests/test_package/test_make_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests generation of pythons script from simulation file."""

import tidy3d as td
from make_script import main

Expand Down
1 change: 1 addition & 0 deletions tests/test_plugins/test_design.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the parameter sweep plugin."""

import pytest
import numpy as np
import tidy3d as td
Expand Down
41 changes: 41 additions & 0 deletions tests/test_plugins/test_mode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..utils import assert_log_level, log_capture, cartesian_to_unstructured # noqa: F401
from tidy3d import ScalarFieldDataArray
from tidy3d.web.core.environment import Env
from tidy3d.components.data.monitor_data import ModeSolverData


WG_MEDIUM = td.Medium(permittivity=4.0, conductivity=1e-4)
Expand Down Expand Up @@ -836,3 +837,43 @@ def test_mode_solver_method_defaults():

sim = ms.sim_with_monitor(name="test")
assert np.allclose(sim.monitors[-1].freqs, ms.freqs)


def test_mode_solver_web_run_batch():
"""Testing run_batch function for the web mode solver."""
wav = 1.5
wav_min = 1.4
wav_max = 1.5
num_freqs = 5
num_of_sims = 3
freqs = np.linspace(td.C_0 / wav_min, td.C_0 / wav_max, num_freqs)

simulation = td.Simulation(
size=SIM_SIZE,
grid_spec=td.GridSpec(wavelength=wav),
structures=[WAVEGUIDE],
run_time=1e-12,
boundary_spec=td.BoundarySpec.all_sides(boundary=td.PML()),
)

# create a list of mode solvers
mode_solver_list = [None] * num_of_sims

# create three different mode solvers with different number of modes specifications
for i in range(num_of_sims):
mode_solver_list[i] = ModeSolver(
simulation=simulation,
plane=PLANE,
mode_spec=td.ModeSpec(
num_modes=i + 1,
target_neff=2.0,
),
freqs=freqs,
direction="+",
)

# Run mode solver one at a time
results = msweb.run_batch(mode_solver_list, verbose=False)

assert all(isinstance(x, ModeSolverData) for x in results)
assert (results[i].n_eff.shape == (num_freqs, i + 1) for i in range(num_of_sims))
1 change: 1 addition & 0 deletions tidy3d/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" command-line interface. For instructions run `python -m tidy3d --help` """

import sys
import argparse

Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""global configuration / base class for pydantic models used to make simulation."""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base_sim/data/monitor_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract base for monitor data structures."""

from __future__ import annotations
from abc import ABC

Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base_sim/data/sim_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract base for simulation data structures."""

from __future__ import annotations
from typing import Dict, Tuple, Union

Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base_sim/monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract bases for classes that define how data is recorded from simulation."""

from abc import ABC, abstractmethod
from typing import Tuple

Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base_sim/simulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract base for defining simulation classes of different solvers"""

from __future__ import annotations

from abc import ABC, abstractmethod
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/base_sim/source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Abstract base for classes that define simulation sources."""

from __future__ import annotations
from abc import ABC, abstractmethod
import pydantic.v1 as pydantic
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/bc_placement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines placements for boundary conditions."""

from __future__ import annotations

from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/boundary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines electromagnetic boundary conditions"""

from __future__ import annotations

from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/data/data_array.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Storing tidy3d data at it's most fundamental level as xr.DataArray objects"""

from __future__ import annotations
from typing import Dict, List, Union
from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/data/dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Collections of DataArrays."""

from __future__ import annotations

from abc import ABC, abstractmethod
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Monitor Level Data, store the DataArrays associated with a single monitor."""

from __future__ import annotations

from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/data/sim_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Simulation Level Data """

from __future__ import annotations
from typing import Callable, Tuple, Union
from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/data/dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""EME dataset"""

from __future__ import annotations


Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/data/monitor_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""EME monitor data"""

from __future__ import annotations

from typing import Union
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/data/sim_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""EME simulation data"""

from __future__ import annotations

from typing import Tuple, Union, Optional, Literal
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/grid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines cells for the EME simulation."""

from __future__ import annotations

from typing import List, Union, Tuple, Literal
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""EME monitors"""

from __future__ import annotations

import pydantic.v1 as pd
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/simulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines EME simulation class."""

from __future__ import annotations

from typing import Tuple, List, Dict, Optional, Literal
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/eme/sweep.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines sweep settings for the EME simulation."""

from __future__ import annotations

from typing import List, Union
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/field_projection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Near field to far field transformation plugin
"""

from __future__ import annotations
from typing import Dict, Tuple, Union, List
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/geometry/mesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mesh-defined geometry."""

from __future__ import annotations

from abc import ABC
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/geometry/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for geometry manipulation."""

from __future__ import annotations
from typing import Union, Tuple
from math import isclose
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/geometry/utils_2d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for 2D geometry manipulation."""

import numpy as np
import shapely
from typing import Tuple, List
Expand Down
1 change: 1 addition & 0 deletions tidy3d/components/grid/grid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines the FDTD grid."""

from __future__ import annotations
from typing import Tuple, List, Union

Expand Down
Loading