Skip to content

Commit 0d22caa

Browse files
committed
docs(config): docs for new config system
1 parent dc01be1 commit 0d22caa

File tree

8 files changed

+289
-41
lines changed

8 files changed

+289
-41
lines changed

docs/api/configuration.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
tidy3d.config.config
19+
20+
Legacy Compatibility
21+
--------------------
22+
23+
.. autosummary::
24+
:toctree: _autosummary/
25+
:template: module.rst
26+
27+
tidy3d.config.LegacyConfigWrapper
28+
tidy3d.config.Env
29+
tidy3d.config.Environment
30+
tidy3d.config.EnvironmentConfig
31+
32+
Registration Utilities
33+
----------------------
34+
35+
.. autosummary::
36+
:toctree: _autosummary/
37+
:template: module.rst
38+
39+
tidy3d.config.register_section
40+
tidy3d.config.register_plugin
41+
tidy3d.config.register_handler
42+
tidy3d.config.get_sections
43+
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.config
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/configuration/index.rst

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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 ``tidy3d.config`` module keeps all of this in one place
9+
through a single object called ``config``. This page explains how it behaves,
10+
where values are stored, and how to keep your changes consistent across
11+
sessions.
12+
13+
Getting Started
14+
---------------
15+
16+
Most users only need the following import::
17+
18+
from tidy3d.config 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("customer")
113+
config.web.api_endpoint = "https://example.com"
114+
config.save()
115+
116+
This writes ``profiles/customer.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+
Plugin Settings
132+
---------------
133+
134+
Plugins can register their own sections so their options appear under
135+
``config.plugins``. A typical plugin exposes a model decorated with
136+
``@register_plugin``::
137+
138+
from tidy3d.config.sections import ConfigSection
139+
from tidy3d.config import register_plugin
140+
141+
@register_plugin("sample")
142+
class SamplePluginConfig(ConfigSection):
143+
enabled: bool = False
144+
threshold: float = 0.5
145+
146+
After the plugin is imported, you can read or modify its settings with::
147+
148+
config.plugins.sample.enabled = True
149+
config.save()
150+
151+
If the plugin registers later in the session, previously saved values are
152+
loaded automatically.
153+
154+
Command Line Helpers
155+
--------------------
156+
157+
Use ``tidy3d configure`` to store your API key in ``config.toml``. The command
158+
creates the directory if it is missing and updates only the ``web`` section.
159+
160+
If you have older files in ``~/.tidy3d``, run ``tidy3d config migrate`` to move
161+
them into the new location described above. The command copies the legacy files
162+
into the canonical directory, leaving the originals untouched unless you pass
163+
``--delete-legacy``. Use ``--overwrite`` if you have already started using the
164+
new location and want to replace those files with the legacy versions.
165+
166+
Legacy Access Points
167+
--------------------
168+
169+
Older code paths such as ``tidy3d.config.logging_level`` and ``tidy3d.config.Env``
170+
still work. They emit a ``DeprecationWarning`` each time you use them to help
171+
you transition to the modern interface. See :doc:`migration` for advice on
172+
updating scripts that depend on these names.
173+
174+
Next Steps
175+
----------
176+
177+
- :doc:`migration`
178+
- :doc:`../api/configuration`

docs/configuration/migration.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.toml`` 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.
32+
33+
Working Safely With Existing Scripts
34+
------------------------------------
35+
36+
- Prefer the new attribute paths (``config.logging.level``) in fresh code.
37+
- When editing older notebooks, import ``warnings`` and silence specific
38+
deprecations temporarily if needed::
39+
40+
import warnings
41+
warnings.filterwarnings("ignore", category=DeprecationWarning)
42+
43+
- After updating your scripts, remove the filter so you notice future changes.
44+
45+
Need Help?
46+
----------
47+
48+
Reach out through the `Tidy3D Discussions board <https://github.com/flexcompute/tidy3d/discussions>`_
49+
or contact [email protected] if you hit any issues while upgrading.

docs/extras/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ You can check whether local subpixel averaging is turned on::
6666

6767
tidy3d.packaging.tidy3d_extras["use_local_subpixel"]
6868

69+
For a broader overview of configuration options and how they are stored, see
70+
:doc:`../configuration/index`.
71+
6972
Licenses
7073
--------
7174

docs/index.rst

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Get Started
5252
5353
tidy3d configure --apikey=XXX
5454
55-
And enter your API key when prompted.
56-
57-
For more detailed installation instructions, see `this page <./install.html>`_.
55+
For more detailed installation instructions, see `this page <./install.html>`_,
56+
and refer to :doc:`configuration/index` if you would like to fine-tune your
57+
settings.
5858

5959
.. group-tab:: On Windows |:window:|
6060

@@ -75,22 +75,12 @@ Get Started
7575
pip install pipx
7676
pipx run tidy3d configure --apikey=XXX
7777
78-
If you're running into trouble, you may need to manually set the API key directly in the configuration file where Tidy3D looks for it.
79-
You need to place the ``$HOME/.tidy3d/config`` file in your home directory such as ``C:\Users\username\`` (where ``username`` is your username).
80-
81-
The API key must be in a file called ``$HOME/.tidy3d/config`` located in your home directory, with the following contents
82-
83-
.. code-block:: bash
84-
85-
apikey = "XXX"
86-
87-
You can manually set up your file like this, or do it through the command line line:
88-
89-
.. code-block:: bash
90-
91-
echo 'apikey = "XXX"' > ~/.tidy3d/config
92-
93-
Note the quotes around `XXX`.
78+
If you're running into trouble, you may need to manually set the API key
79+
directly in the configuration file where Tidy3D looks for it. The ``tidy3d
80+
configure`` command stores the API key for you. If you prefer to manage the
81+
file yourself, place ``config.toml`` in the directory described in
82+
:doc:`configuration/index` (for example ``~/.config/tidy3d`` on macOS/Linux
83+
or ``%APPDATA%\\tidy3d`` on Windows).
9484

9585
.. group-tab:: In the Cloud |:cloud:|
9686

@@ -249,6 +239,7 @@ Contents
249239
:maxdepth: 2
250240

251241
install
242+
configuration/index
252243
lectures/index
253244
notebooks/docs/index
254245
faq/docs/index
@@ -260,6 +251,3 @@ Contents
260251
changelog
261252
About our Solver <https://www.flexcompute.com/tidy3d/solver/>
262253

263-
264-
265-

docs/install.rst

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,9 @@ Alternatively, the API key can be set up using the environment variable ``SIMCLO
7878
7979
export SIMCLOUD_APIKEY="XXX"
8080
81-
Finally, one may manually set the API key directly in the configuration file where Tidy3D looks for it.
82-
83-
The API key must be in a file called ``.tidy3d/config`` located in your home directory, with the following contents
84-
85-
.. code-block:: python
86-
87-
apikey = "XXX"
88-
89-
You can manually set up your file like this, or do it through the command line line:
90-
91-
.. code-block:: python
92-
93-
echo 'apikey = "XXX"' > ~/.tidy3d/config
94-
95-
Note the quotes around `XXX`.
96-
97-
Note that Windows users will most likely need to place the ``.tidy3d/config`` file in their ``C:\Users\username\`` directory (where ``username`` is your username).
81+
Finally, one may manually set the API key directly in the configuration file
82+
where Tidy3D looks for it. The path and file format differ slightly between
83+
platforms; see :doc:`configuration/index` for the up-to-date layout.
9884

9985

10086

0 commit comments

Comments
 (0)