Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
621b8d6
add automatic tidy3d matplotlib styles
frederikschubertflex May 5, 2025
3b3983c
refactor utils to remove get_hex_formatted_string function that is us…
frederikschubertflex May 5, 2025
6529dcd
add unit test for setting the matplotlib styles on import
frederikschubertflex May 6, 2025
4b9dc45
add changelog entry and export for the the reset_previous_style function
frederikschubertflex May 7, 2025
cc4bb49
add docstring to rcParams test
frederikschubertflex May 7, 2025
efd4fbd
add test for validating the material library rich representation
frederikschubertflex May 7, 2025
ff8e6c1
cleanup unused imports
frederikschubertflex May 7, 2025
209dcbf
fix formatting issues
frederikschubertflex May 8, 2025
67bcc96
move viz.py into its own module to prepare for refactoring
frederikschubertflex May 9, 2025
71836bb
add the flexcompute tint palette
frederikschubertflex May 12, 2025
da89241
cleanup viz structure
frederikschubertflex May 16, 2025
a12b01b
refactor: split up large viz.py and add documentation
frederikschubertflex May 19, 2025
c1f9fc8
refactor: re-add fix to plot_sim_3d
frederikschubertflex May 19, 2025
4ece35c
fix: rename reset_previous_style to restore_matplotlib_rcparams
frederikschubertflex May 20, 2025
fb2eaad
fix: typo
frederikschubertflex May 20, 2025
0028009
fix: move tidy3d style into mplstyle file
frederikschubertflex May 20, 2025
8bb7f07
Merge remote-tracking branch 'origin' into frederikschubertflex/rcparams
frederikschubertflex May 20, 2025
3985372
revert typo
frederikschubertflex May 20, 2025
254314e
Merge remote-tracking branch 'origin' into frederikschubertflex/rcparams
frederikschubertflex May 20, 2025
c875ae5
fix: resolve merge conflict
frederikschubertflex May 20, 2025
c3020fb
fix: use exact module
frederikschubertflex May 20, 2025
a11c1d0
fix: lint issues
frederikschubertflex May 20, 2025
70230df
Merge branch 'develop' into frederikschubertflex/rcparams
frederikschubertflex May 21, 2025
f524559
Merge branch 'develop' into frederikschubertflex/rcparams
frederikschubertflex May 23, 2025
b5f62ac
Merge branch 'develop' into frederikschubertflex/rcparams
frederikschubertflex May 23, 2025
b3ef676
Merge branch 'develop' into frederikschubertflex/rcparams
frederikschubertflex May 23, 2025
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `eps_lim` keyword argument to `Simulation.plot_eps()` for manual control over the permittivity color limits.
- Added `thickness` parameter to `LossyMetalMedium` for computing surface impedance of a thin conductor.
- `priority` field in `Structure` and `MeshOverrideStructure` for setting the behavior in structure overlapping region. When its value is `None`, the priority is automatically determined based on the material property and simulation's `structure_priority_mode`.
- Automatically apply `matplotlib` styles when importing `tidy3d` which can be reverted via the `td.restore_matplotlib_rcparams()` function.

### Fixed
- Fixed bug in broadband adjoint source creation when forward simulation had a pulse amplitude greater than 1 or a nonzero pulse phase.
Expand Down
4 changes: 3 additions & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ API |:computer:|
constants
abstract_base
abstract_models
viz

.. include:: /api/simulation.rst
.. include:: /api/boundary_conditions.rst
Expand All @@ -58,4 +59,5 @@ API |:computer:|
.. include:: /api/plugins/index.rst
.. include:: /api/constants.rst
.. include:: /api/abstract_base.rst
.. include:: /api/abstract_models.rst
.. include:: /api/abstract_models.rst
.. include:: /api/viz.rst
11 changes: 11 additions & 0 deletions docs/api/viz.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. currentmodule:: tidy3d

Visualization and Plotting
==========================

.. autosummary::
:toctree: _autosummary/
:template: module.rst

tidy3d.restore_matplotlib_rcparams
tidy3d.VisualizationSpec
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Operating System :: OS Independent",
]
documentation = "https://docs.flexcompute.com/projects/tidy3d/en/latest/"
include = [{ path = "tidy3d/style.mplstyle", format = ["sdist", "wheel"] }]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/flexcompute/tidy3d/issues"
Expand Down Expand Up @@ -82,8 +83,8 @@ pyswarms = { version = "*", optional = true }

# pytorch
torch = [
{ version = "^2.2.0", source = "PyPI", platform = "darwin", optional = true },
{ version = "^2.2.0", source = "torch-cpu", platform = "!=darwin", optional = true },
{ version = "^2.2.0", source = "PyPI", platform = "darwin", optional = true },
{ version = "^2.2.0", source = "torch-cpu", platform = "!=darwin", optional = true },
]

# scikit-rf
Expand Down Expand Up @@ -275,7 +276,7 @@ ignore = [
# TODO: remove --assert=plain when https://github.com/scipy/scipy/issues/22236 is resolved
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' "
markers = [
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
]
env = ["MPLBACKEND=Agg", "OMP_NUM_THREADS=1"]
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
Expand Down
11 changes: 9 additions & 2 deletions tests/test_components/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
import tidy3d as td
from tidy3d import Box, Medium, Simulation, Structure
from tidy3d.components.viz import Polygon, set_default_labels_and_title
from tidy3d.components.viz import Polygon, restore_matplotlib_rcparams, set_default_labels_and_title
from tidy3d.constants import inf
from tidy3d.exceptions import Tidy3dKeyError

Expand Down Expand Up @@ -222,7 +222,7 @@ def plot_with_multi_viz_spec(alphas, facecolors, edgecolors, rng, use_viz_spec=T

def test_no_matlab_install(monkeypatch):
"""Test that the `VisualizationSpec` only throws a warning on validation if matplotlib is not installed."""
monkeypatch.setattr("tidy3d.components.viz.MATPLOTLIB_IMPORTED", False)
monkeypatch.setattr("tidy3d.components.viz.visualization_spec.MATPLOTLIB_IMPORTED", False)

EXPECTED_WARNING_MSG_PIECE = (
"matplotlib was not successfully imported, but is required to validate colors"
Expand Down Expand Up @@ -330,3 +330,10 @@ def test_sim_plot_structures_fill():
for patch in structure_patches[:1]:
assert patch.get_fill(), "Should be filled when True"
assert patch.get_facecolor() != "none", "Face color should be set"


def test_tidy3d_matplotlib_style_application_on_import():
"""Test restore_matplotlib_rcparams() to reset the automatically applied matplotlib.rcParams"""
assert mpl.rcParams.get("axes.edgecolor") == "#ECEBEA"
restore_matplotlib_rcparams()
assert mpl.rcParams.get("axes.edgecolor") == mpl.rcParamsDefault.get("axes.edgecolor")
7 changes: 7 additions & 0 deletions tests/test_material_library/test_material_library.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests material library functions and pretty printing"""

import tidy3d as td
from rich.console import Console
from tidy3d.material_library.material_library import MaterialItemUniaxial


Expand All @@ -9,6 +10,12 @@ def test_material_library_summary():
print(td.material_library)


def test_material_library_rich_console():
"""Test the rich representation of the material library which validates its styles etc."""
console = Console()
console.print(td.material_library)


def test_material_summary():
"""Test the string method for each material in the material library."""

Expand Down
3 changes: 2 additions & 1 deletion tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
SpaceTimeModulation,
)
from .components.transformation import RotationAroundAxis
from .components.viz import VisualizationSpec
from .components.viz import VisualizationSpec, restore_matplotlib_rcparams

# config
from .config import config
Expand Down Expand Up @@ -649,6 +649,7 @@ def set_logging_level(level: str) -> None:
"PECConformal",
"SurfaceImpedance",
"VisualizationSpec",
"restore_matplotlib_rcparams",
"EMESimulation",
"EMESimulationData",
"EMEMonitor",
Expand Down
Loading