Skip to content

Commit 691741b

Browse files
committed
docs(config): docs for new config system
1 parent 4787f47 commit 691741b

File tree

14 files changed

+594
-54
lines changed

14 files changed

+594
-54
lines changed

docs/_ext/custom-robots.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
def process_robots_txt(app, exception):
77
# Get the path to the robots.txt file
88
robots_file = os.path.join(app.outdir, "robots.txt")
9-
10-
# Read the contents of the robots.txt file
119
with open(robots_file) as f:
1210
contents = f.read()
1311

14-
# Modify the contents as needed
15-
# site_map = app.config['html_baseurl'] + app.config['version'] + app.config['language'] + 'sitemap.xml'
1612
site_map = "/".join(
1713
[app.config["html_baseurl"], app.config["language"], app.config["version"], "sitemap.xml"]
1814
).replace("//", "/")
19-
new_content = f"\nSitemap: {site_map}"
20-
contents += new_content
15+
contents += f"\nSitemap: {site_map}"
2116

2217
# Update the robots.txt file with the modified contents
2318
with open(robots_file, "w") as f:

docs/_templates/module.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939

4040
.. rubric:: Inherited Common Usage
4141

42-
.. include:: ../_custom_autosummary/{{ fullname }}.rst
42+
.. include:: ../_custom_autosummary/{{ fullname }}.rst
43+
:optional:

docs/api/configuration.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Configuration API
2+
=================
3+
4+
.. currentmodule:: tidy3d.config
5+
6+
The objects and helpers below expose the public configuration interface.
7+
8+
Manager and Helpers
9+
-------------------
10+
11+
.. autosummary::
12+
:toctree: _autosummary/
13+
:template: module.rst
14+
15+
tidy3d.config.ConfigManager
16+
tidy3d.config.get_manager
17+
tidy3d.config.reload_config
18+
19+
Legacy Compatibility
20+
--------------------
21+
22+
.. autosummary::
23+
:toctree: _autosummary/
24+
:template: module.rst
25+
26+
tidy3d.config.LegacyConfigWrapper
27+
tidy3d.config.Environment
28+
tidy3d.config.EnvironmentConfig
29+
30+
Registration Utilities
31+
----------------------
32+
33+
.. autosummary::
34+
:toctree: _autosummary/
35+
:template: module.rst
36+
37+
tidy3d.config.register_section
38+
tidy3d.config.register_plugin
39+
tidy3d.config.register_handler
40+
tidy3d.config.get_sections
41+
tidy3d.config.get_handlers

docs/api/constants.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Tidy3D Configuration
3535
:toctree: _autosummary/
3636
:template: module.rst
3737

38-
tidy3d.config.Tidy3dConfig
38+
tidy3d.config.ConfigManager
3939

4040
Default Absorber Parameters
4141
----------------------------
@@ -92,4 +92,4 @@ Precision & Comparator Values
9292
tidy3d.constants.fp_eps
9393
tidy3d.constants.pec_val
9494
tidy3d.constants.LARGE_NUMBER
95-
tidy3d.constants.GLANCING_CUTOFF
95+
tidy3d.constants.GLANCING_CUTOFF

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ API |:computer:|
1818
output_data
1919
analytic_beams
2020
utilities
21+
configuration
2122
mesh/index
2223
heat/index
2324
charge/index

docs/api/simulation.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Logging
6161
:toctree: _autosummary/
6262
:template: module.rst
6363

64-
tidy3d.config.logging_level
65-
tidy3d.set_logging_file
64+
tidy3d.log.set_logging_level
65+
tidy3d.log.set_log_suppression
66+
tidy3d.log.set_logging_file
6667

6768
~~~~

docs/api/sources.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Sources
66
Overview
77
--------
88

9-
Sources in Tidy3D provide the necessary excitation to investigate the EM behaviour of the structures under simulation. The type of source used in a simulation tends to be very application-specific. For instance, a ``PlaneWave`` source may be used for a unit cell simulation in a metalens; whereas a ``ModeSource`` would be more appropriate for a waveguide crossing problem.
9+
Sources in Tidy3D provide the necessary excitation to investigate the EM behavior of the structures under simulation. The type of source used in a simulation tends to be very application-specific. For instance, a ``PlaneWave`` source may be used for a unit cell simulation in a metalens; whereas a ``ModeSource`` would be more appropriate for a waveguide crossing problem.
1010

1111
A generic source can be thought of as composed of two parts: a spatial profile and a temporal profile. The former dictates the field distribution in space, whereas the latter determines the frequency band covered by the source, and by extension, the overall simulation.
1212

docs/configuration/index.rst

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Configuration Guide |:gear:|
2+
============================
3+
4+
.. highlight:: python
5+
6+
Working with cloud simulations usually requires a handful of settings such as
7+
your API key, the active environment, and any local tweaks you make while
8+
experimenting. The ``config`` object (available via ``from tidy3d import config``)
9+
keeps all of this in one place through a single interface. This page explains
10+
how it behaves, where values are stored, and how to keep your changes
11+
consistent across sessions. For a catalog of every option, see :doc:`reference`.
12+
13+
Getting Started
14+
---------------
15+
16+
Most users only need the following import::
17+
18+
from tidy3d import config
19+
20+
You can then read or update sections just like attributes::
21+
22+
# read values
23+
print(config.web.api_endpoint)
24+
print(config.logging.level)
25+
26+
# update values
27+
config.logging.level = "DEBUG"
28+
config.web.timeout = 60
29+
config.save()
30+
31+
The ``save()`` call writes your edits to disk so the same settings load the
32+
next time you import ``tidy3d``.
33+
34+
Where Settings Are Stored
35+
-------------------------
36+
37+
Tidy3D chooses a configuration directory the first time you import the module.
38+
The location depends on your operating system:
39+
40+
.. list-table:: Default configuration directory
41+
:widths: 30 70
42+
:header-rows: 1
43+
44+
* - Platform
45+
- Path
46+
* - macOS / Linux
47+
- ``~/.config/tidy3d``
48+
* - Windows
49+
- ``C:\Users\<you>\.config\tidy3d``
50+
51+
You can override this by setting the ``TIDY3D_BASE_DIR`` environment variable
52+
*before* importing ``tidy3d``. When it is present, the config files are kept in
53+
``<base>/.tidy3d``. If the chosen location is not writable, Tidy3D falls back to
54+
a temporary directory and warns that the settings will not persist.
55+
56+
Files Inside the Directory
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
59+
- ``config.toml`` – base settings shared by all profiles.
60+
- ``profiles/<name>.toml`` – optional overrides for custom profiles. Each file
61+
only contains the differences from the base settings.
62+
63+
Priority Order
64+
--------------
65+
66+
Whenever you read ``config.<section>.<field>``, the value comes from the highest
67+
priority source in the list below. Lower entries only apply when the ones above
68+
them do not set a value.
69+
70+
1. Runtime changes you make in the current Python session.
71+
2. Environment variables (``TIDY3D_<SECTION>__<FIELD>``).
72+
3. Profile overrides from ``profiles/<name>.toml``.
73+
4. The base ``config.toml`` file.
74+
5. Built-in profiles (for example ``prod`` and ``dev``) bundled with Tidy3D.
75+
6. Default values defined by the software.
76+
77+
This means environment variables always win over ``config.toml``, and any
78+
attribute you set in code wins over everything else until you discard it or
79+
call ``save()``.
80+
81+
Making Changes That Last
82+
------------------------
83+
84+
Runtime Updates
85+
~~~~~~~~~~~~~~~
86+
87+
Assignments like ``config.logging.level = "INFO"`` apply immediately but only
88+
live in memory. They affect new simulations started in the same interpreter but
89+
disappear when the process exits.
90+
91+
Saving to Disk
92+
~~~~~~~~~~~~~~
93+
94+
Call ``config.save()`` to write the current profile to disk. The method removes
95+
environment-variable overrides automatically so you never persist an API key or
96+
other secret that was loaded from the shell. To store the full set of values,
97+
including defaults, pass ``include_defaults=True``::
98+
99+
config.save(include_defaults=True)
100+
101+
Profiles
102+
--------
103+
104+
Tidy3D ships with built-in profiles such as ``prod`` and ``dev``. Switch between
105+
them with::
106+
107+
config.switch_profile("dev")
108+
109+
To create your own profile, switch to a new name, edit settings, then call
110+
``save()``::
111+
112+
config.switch_profile("my_profile")
113+
config.web.api_endpoint = "https://example.com"
114+
config.save()
115+
116+
This writes ``profiles/my_profile.toml`` containing only the adjustments you
117+
made. Use ``config.profiles.list()`` to discover available built-in and user
118+
profiles.
119+
120+
Environment Variables
121+
---------------------
122+
123+
Environment variables let you override individual options without touching any
124+
files. The naming pattern is ``TIDY3D_<SECTION>__<FIELD>``, for example::
125+
126+
export TIDY3D_LOGGING__LEVEL=WARNING
127+
128+
Supported variables take effect the next time you import ``tidy3d``. Remove a
129+
variable or clear the shell environment to restore the lower priority setting.
130+
131+
Command Line Helpers
132+
--------------------
133+
134+
Use ``tidy3d configure`` to store your API key in ``config.toml``. The command
135+
creates the directory if it is missing and updates only the ``web`` section.
136+
137+
If you have older files in ``~/.tidy3d``, run ``tidy3d config migrate`` to move
138+
them into the new location described above. The command copies the legacy files
139+
into the canonical directory, leaving the originals untouched unless you pass
140+
``--delete-legacy``. Use ``--overwrite`` if you have already started using the
141+
new location and want to replace those files with the legacy versions.
142+
143+
Legacy Access Points
144+
--------------------
145+
146+
Older code paths such as ``tidy3d.config.logging_level`` and ``tidy3d.config.Env``
147+
still work. They emit a ``DeprecationWarning`` each time you use them to help
148+
you transition to the modern interface. See :doc:`migration` for advice on
149+
updating scripts that depend on these names.
150+
151+
Next Steps
152+
----------
153+
154+
- :doc:`reference`
155+
- :doc:`migration`
156+
- :doc:`../api/configuration`

docs/configuration/migration.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Upgrading Existing Setups
2+
=========================
3+
4+
This short note highlights the differences you may notice when moving from
5+
earlier versions of Tidy3D to the current configuration manager.
6+
7+
File Locations
8+
--------------
9+
10+
- Previous releases stored settings in ``~/.tidy3d`` on all platforms. The new
11+
manager now prefers the platform-specific paths described in
12+
:doc:`index`.
13+
- Your existing ``~/.tidy3d/config`` is still respected. Run
14+
``tidy3d config migrate`` if you would like to copy it into the new directory.
15+
Append ``--overwrite`` to replace any files that already exist in the new
16+
location, and ``--delete-legacy`` to remove ``~/.tidy3d`` after the copy.
17+
18+
Environment Switching
19+
---------------------
20+
21+
- The ``Env`` helper remains available. Calls such as ``Env.dev.active()`` now
22+
forward to the new manager and produce a ``DeprecationWarning`` to encourage
23+
the modern API, e.g. ``config.switch_profile("dev")``.
24+
25+
Legacy Attributes
26+
-----------------
27+
28+
- Shorthand properties ``config.logging_level``, ``config.log_suppression``,
29+
and ``config.use_local_subpixel`` still work and set the equivalent fields in
30+
``config.logging`` or ``config.simulation``. Each call raises a warning so
31+
you can update scripts at your own pace.

0 commit comments

Comments
 (0)