### Add Nexus to Existing Configuration Example Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Example of adding Nexus configuration to an existing setup, preserving the API key. ```bash # Add Nexus to existing configuration (preserves API key) tidy3d configure --nexus-url http://nexus.company.com ``` -------------------------------- ### Install Tidy3D with Trimesh Support Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Example of installing Tidy3D with the 'trimesh' optional dependency group for enhanced mesh handling. ```bash pip install "tidy3d[trimesh]" ``` -------------------------------- ### Simple Nexus Configuration Example Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Example of a simple Nexus configuration using the nexus-url option. ```bash # Simple configuration using nexus-url (recommended) tidy3d configure --apikey YOUR_KEY \ --nexus-url http://nexus.company.com ``` -------------------------------- ### Full Nexus Configuration Example Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Example demonstrating a full Nexus configuration with all available options, including S3, SSL, and caching. ```bash # Full configuration with all options tidy3d configure --apikey YOUR_KEY \ --api-endpoint https://api.company.com/tidy3d-api \ --website-endpoint https://tidy3d.company.com \ --s3-region eu-west-1 \ --s3-endpoint https://s3.company.com:9000 \ --ssl-verify \ --enable-caching ``` -------------------------------- ### Install Tidy3D-beta from TestPyPI Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/cli/readme.md Install the 'tidy3d-beta' package from TestPyPI in a clean environment. This command is useful for testing installation before releasing to the main PyPI. ```bash python -m pip install --index-url https://test.pypi.org/simple/ tidy3d-beta ``` -------------------------------- ### Configure Nexus with Individual Endpoints Example Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Example of configuring Nexus by specifying individual API and website endpoints. ```bash # Configure individual endpoints tidy3d configure --apikey YOUR_KEY \ --api-endpoint http://nexus.company.com/tidy3d-api \ --website-endpoint http://nexus.company.com/tidy3d ``` -------------------------------- ### Tidy3D Agent Instructions for AI Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/index.rst Instructions for AI agents on setting up and using the Tidy3D MCP for documentation and simulation code generation. It guides the agent to use specific Flexcompute documentation search tools and consult relevant class docstrings and example notebooks. ```markdown # Tidy3D Agent Instructions ## MCP Setup If the Tidy3D plugin or MCP server is not already configured, see: https://docs.flexcompute.com/projects/tidy3d/en/latest/ai/flex_agent.html#agent-plugins ## Workflow Use `search_flexcompute_docs` and `fetch_flexcompute_doc` from the Tidy3D MCP as your primary documentation source throughout the session. Before writing simulation code: 1. Search for "Simulation Tips for AI Agents" — workflow patterns, pitfalls, and checklists. 2. Search for the relevant class docstrings — they contain selection guides, extraction patterns, and practical advice. 3. Search for example notebooks related to the device or workflow you are building. ``` -------------------------------- ### Verify tidy3d-extras Installation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/extras/index.rst Verify the installation of the tidy3d-extras package by printing its version. ```python import tidy3d_extras as tde print(tde.__version__) ``` -------------------------------- ### Install Tidy3D Python API Locally Source: https://github.com/flexcompute/tidy3d/blob/develop/README.md Use this command to install the Tidy3D Python API locally. Ensure you have pip installed. ```bash pip install --user tidy3d tidy3d configure --apikey=XXX ``` -------------------------------- ### Initialize and Add Packages with uv Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/cursor_extension.rst Use 'uv init' to create a new project, 'uv add' to install tidy3d, jupyter, numpy, and matplotlib, and 'uv sync' to ensure all dependencies are installed. ```bash # Install uv from https://docs.astral.sh/uv/getting-started/installation/ uv init my-tidy3d-project cd my-tidy3d-project uv add tidy3d jupyter numpy matplotlib uv sync ``` -------------------------------- ### Install Tidy3D with Multiple Optional Groups Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Install Tidy3D with multiple optional dependency groups simultaneously, such as 'design' and 'trimesh'. ```bash pip install "tidy3d[design,trimesh]" ``` -------------------------------- ### Quick Example: Simulate a 3D Dielectric Box Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst A brief example demonstrating how to simulate a 3D dielectric box in Tidy3D and plot the field pattern. ```python # Example code for simulating a 3D dielectric box will go here. ``` -------------------------------- ### Start Live 3D Viewer Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/cursor_extension.rst Launch the live 3D viewer for a simulation file. Specify the file path and optionally a symbol. ```python tidy3d_start_viewer(file, symbol) ``` -------------------------------- ### Add KLayout to System PATH (macOS Example) Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/klayout/drc/README.md Example of how to add the KLayout executable to your system's PATH on macOS by modifying the .zshrc file. This is necessary if check_installation() cannot find KLayout. ```bash export PATH="$PATH:/Applications/klayout.app/Contents/MacOS" ``` -------------------------------- ### Install tidy3d with extras Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/extras/index.rst Install tidy3d and the extras plugin using pip. Ensure your Tidy3D version matches the extras version. ```bash pip install "tidy3d[extras]" ``` -------------------------------- ### Verify Tidy3D Installation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Verifies a successful Tidy3D installation by printing the client version. ```bash python -c "import tidy3d as td; print(td.__version__)" ``` -------------------------------- ### Install Tidy3D in Hosted Environment Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Installs the Tidy3D Python API in a hosted environment like Google Colab and configures it with an API key. ```bash pip install tidy3d ``` ```python import tidy3d.web as web web.configure("XXX") ``` -------------------------------- ### Configure Tidy3D API Key on Windows using pipx Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Configures the tidy3d package with an API key using pipx for automatic setup. Requires pipx to be installed. ```bash pip install pipx pipx run tidy3d configure --apikey=XXX ``` -------------------------------- ### Install Tidy3D with Design Plugin Dependencies Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Install Tidy3D with the 'design' plugin dependencies for design space exploration and optimization. ```bash pip install "tidy3d[design]" ``` -------------------------------- ### Check KLayout Installation Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/klayout/drc/README.md Verifies if the KLayout executable can be found in the system PATH. Prints the full path if found, otherwise returns None. ```python from tidy3d.plugins.klayout import check_installation # Prints the full path to the executable if found, otherwise returns None print(check_installation()) ``` -------------------------------- ### Install PyTorch Wrapper Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/pytorch.rst Install the PyTorch wrapper for Tidy3D using pip. This command installs the necessary package to enable PyTorch integration. ```bash pip install tidy3d[pytorch] ``` -------------------------------- ### Check Installation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/klayout.rst Utility function to check if KLayout is installed and accessible. ```APIDOC ## plugins.klayout.check_installation ### Description Checks if KLayout is installed and available in the system's PATH. ### Function Signature `check_installation()` ### Returns `bool` - True if KLayout is installed, False otherwise. ``` -------------------------------- ### Create and Combine ModeAmp and ModePower Metrics Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/expressions/README.md Demonstrates creating ModeAmp and ModePower metrics and combining them into an expression for an objective function. Ensure the monitor names and frequencies match your simulation setup. ```python from tidy3d.plugins.expressions import ModeAmp, ModePower # Create metrics mode_coeff = ModeAmp(monitor_name="monitor1", freqs=[1.0]) mode_power = ModePower(monitor_name="monitor2", freqs=[1.0]) # Define an objective function using metrics f = abs(mode_coeff) - mode_power / 2 # Display the expression print(f) ``` -------------------------------- ### Developer Installation of Tidy3D Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Install Tidy3D with all optional dependencies included, suitable for developers. ```bash pip install "tidy3d[dev]" ``` -------------------------------- ### Install Tidy3D with Optional Dependencies Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Install Tidy3D with specific optional dependency groups like 'gdstk', 'trimesh', 'vtk', or 'heatcharge' to enable additional features. ```bash pip install "tidy3d[dependency_group]" ``` -------------------------------- ### Install Specific Version of Tidy3D-beta from TestPyPI Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/cli/readme.md Install a specific version of 'tidy3d-beta' from TestPyPI. This is helpful when encountering issues with the latest version or when testing a particular release. ```bash python -m pip install --index-url https://test.pypi.org/simple/ tidy3d-beta==1.8.0 ``` -------------------------------- ### Install Tidy3D Plugin in Claude Code Source: https://github.com/flexcompute/tidy3d/blob/develop/README.md Use these commands to add the Flexcompute plugin marketplace and install the Tidy3D plugin within Claude Code. ```text /plugin marketplace add flexcompute/plugin-marketplace /plugin install tidy3d@flexcompute ``` -------------------------------- ### Install Tidy3D on Linux/MacOS Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Installs the latest stable Python library for creating, managing, and postprocessing simulations. ```bash pip install --user tidy3d ``` -------------------------------- ### Import and Configure Tidy3D Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Import the necessary tidy3d modules and configure API key if authentication is needed. This is the initial setup for any tidy3d simulation. ```python # import the tidy3d package and configure it with your API key import numpy as np import tidy3d as td import tidy3d.web as web # web.configure("YOUR API KEY") # if authentication needed, uncomment this line and paste your API key here ``` -------------------------------- ### Run an EME Simulation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/eme/index.rst This snippet shows the basic setup and execution of an EME simulation using `tidy3d.web.run`. It defines the simulation parameters, including geometry, frequencies, propagation axis, and EME grid specification, then runs the simulation and retrieves the scattering matrix. ```python import tidy3d as td import tidy3d.web as web sim = td.EMESimulation( size=(2.0, 2.0, 10.0), structures=[my_waveguide], freqs=[td.C_0 / 1.55], axis=2, eme_grid_spec=td.EMEUniformGrid( num_cells=5, mode_spec=td.EMEModeSpec(num_modes=4), ), ) sim_data = web.run(sim, task_name="my_eme") smatrix = sim_data.smatrix ``` -------------------------------- ### Install Tidy3D Plugin in Claude Code Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/flex_agent.rst Install the Tidy3D plugin from the Flexcompute plugin marketplace in Claude Code. Reload plugins if Claude Code is already running. ```text /plugin marketplace add flexcompute/plugin-marketplace /plugin install tidy3d@flexcompute ``` ```text /reload-plugins ``` -------------------------------- ### Install Tidy3D with Extras Plugin Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Install the 'extras' plugin for additional local functionality, including a more accurate local mode solver. Note: This is not compatible with Conda environments. ```bash pip install "tidy3d[extras]" ``` -------------------------------- ### KLayout DRC Runset Example Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/klayout/drc/README.md An example KLayout DRC runset script defining source and report files, and implementing rules for minimum width, space, area, and hole on layer (0,0). ```klayout_drc # Simple DRC rules for testing # Define the source and output (report) source($gdsfile) report("DRC results", $resultsfile) # Checks minimum width of 300 nm input(0, 0).width(300.nm).output("min_width", "minimum width") # Checks minimum gap of 300 nm input(0, 0).space(300.nm).output("min_gap", "minimum gap") # Checks minimum area of 1e5 nm^2 input(0, 0).drc(area < 100000).output("min_area", "minimum area") # Checks minimum hole of 1e5 nm^2 input(0, 0).holes.drc(area < 100000).output("min_hole", "minimum hole") ``` -------------------------------- ### Using AutoImpedanceSpec for Simplified Setup Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/microwave_migration.rst Use `AutoImpedanceSpec` for most cases to automatically compute voltage, current, and impedance from electromagnetic fields. This simplifies the setup for microwave ports. ```python # Simplest form - let Tidy3D auto-compute everything port = WavePort( center=(0, 0, -5), size=(2, 2, 0), direction="+", mode_spec=MicrowaveModeSpec( num_modes=2, impedance_specs=AutoImpedanceSpec() # Works for all modes ), name="simple_port" ) ``` -------------------------------- ### Optimize Simulation Parameters Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/pytorch.rst Optimize simulation parameters using PyTorch optimizers. This example demonstrates how to use an optimizer to adjust a parameter (e.g., structure size) to minimize a loss function. ```python # Example of parameter optimization (requires defining parameters to be optimized) # optimizer = torch.optim.Adam([sim_torch.structures[0].geometry.size], lr=0.01) # ... optimization loop ... # For demonstration, we'll just show how to access and modify a parameter structure_size = sim_torch.structures[0].geometry.size print(f"Original structure size: {structure_size}") # Example of modifying a parameter (e.g., during an optimization loop) # new_size = structure_size * 0.9 # sim_torch.structures[0].geometry.size = new_size # print(f"Modified structure size: {sim_torch.structures[0].geometry.size}") ``` -------------------------------- ### Install and Configure Tidy3D in Jupyter Notebook Source: https://github.com/flexcompute/tidy3d/blob/develop/README.md For hosted Jupyter environments like Google Colab, use these commands at the top of your notebook to install and configure Tidy3D. ```python !pip install tidy3d import tidy3d.web as web web.configure("XXX") ``` -------------------------------- ### Add Flexcompute Marketplace in Codex Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/flex_agent.rst Add the Flexcompute marketplace to Codex and then install the Tidy3D plugin. ```bash codex plugin marketplace add flexcompute/plugin-marketplace ``` -------------------------------- ### Custom Initialization for Topology Design Region Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/invdes/README.md Demonstrates how to create custom parameters for a TopologyDesignRegion using NumPy, including random sampling, mirroring, and normalization. This is useful for setting a specific starting point for optimization. ```python custom_params = np.random.random(design_region.params_shape) custom_params += np.fliplr(custom_params) custom_params /= 2 design_region = design_region.updated_copy( initialization_spec=tdi.CustomInitializationSpec(params=custom_params) ) params0 = design_region.initial_parameters print(params0.shape) ``` -------------------------------- ### Launch Standalone MCP Server Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/flex_agent.rst Launch the Tidy3D MCP server manually using the uvx command. This is for advanced manual setup with other MCP-compatible clients. ```bash uvx tidy3d mcp ``` -------------------------------- ### Create a Field Monitor Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Define a monitor to measure electromagnetic fields. This example sets up a monitor to measure fields across the entire domain at a specific frequency. ```python # create monitor - Measures electromagnetic fields within the entire domain at z=0 monitor = td.FieldMonitor( size=(td.inf, td.inf, 0), freqs=[freq0], name="fields", colocate=True, ) ``` -------------------------------- ### Add Lumped Elements to Simulation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/ports/lumped.rst All lumped elements should be added to the 'lumped_elements' field of the base Simulation instance. This example shows how to include defined resistors and lumped elements in a simulation setup. ```python my_simulation = Simulation( lumped_elements=[my_resistor, my_lumped_element], # ... other simulation parameters ) ``` -------------------------------- ### Migrate Documentation Versions Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/versions/README.md Run this command in the repository root to migrate between documentation versions. ```bash python -m tidy3d.utils.migrate ``` -------------------------------- ### ImpedanceCalculator Initialization Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/impedance_calculator.rst Demonstrates how to initialize the ImpedanceCalculator with voltage and current integration paths. The calculator can infer the method based on which integrals are provided. ```APIDOC ## ImpedanceCalculator Initialization ### Description Initializes the `ImpedanceCalculator` with specified voltage and current integration paths. The choice of integrals determines the impedance calculation method. ### Method `td.ImpedanceCalculator(voltage_integral, current_integral)` ### Parameters - **voltage_integral** (`td.AxisAlignedVoltageIntegral` or `None`) - The voltage integration path. If `None`, the 'P and I method' is used. - **current_integral** (`td.AxisAlignedCurrentIntegral` or `None`) - The current integration contour. If `None`, the 'P and V method' is used. ### Request Example ```python import tidy3d as td # Define voltage integration path voltage_integral = td.AxisAlignedVoltageIntegral( center=(0, 0, 0), size=(0, 0, 2), # Vertical line sign="+", extrapolate_to_endpoints=True, snap_path_to_grid=True ) # Define current integration contour current_integral = td.AxisAlignedCurrentIntegral( center=(0, 0, 0), size=(4, 2, 0), # Rectangular loop sign="+", snap_contour_to_grid=True ) # Create impedance calculator Z_calculator = td.ImpedanceCalculator( voltage_integral=voltage_integral, current_integral=current_integral ) ``` ``` -------------------------------- ### Initialize and Configure Simulation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Combine all simulation components (structures, sources, monitors) into a single simulation object. This includes setting the simulation domain size and grid resolution. ```python # Initialize simulation - Combine all objects together into a single specification to run sim = td.Simulation( size=(4, 3, 3), grid_spec=td.GridSpec.auto(min_steps_per_wvl=25), structures=[square], sources=[source], monitors=[monitor], run_time=120/freq0, ) ``` -------------------------------- ### Install Latest Tidy3D Version Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Installs the latest version of Tidy3D and its dependencies using pip. ```bash pip install tidy3d ``` -------------------------------- ### Using Impedance Calculator with Mode Solver Data Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/impedance_calculator.rst Demonstrates how to run a ModeSimulation and then use the impedance calculator with the resulting mode data. Requires the tidy3d.web library. ```python import tidy3d.web as web # Run mode simulation mode_sim = td.ModeSimulation( size=(10, 10, 0), grid_spec=td.GridSpec.auto(wavelength=0.3), structures=[...], monitors=[mode_monitor], freqs=[1e9, 2e9, 3e9] ) mode_sim_data = web.run(mode_sim, task_name='mode_solver') # Calculate impedance for each mode Z0 = Z_calculator.compute_impedance(mode_sim_data.modes) ``` -------------------------------- ### Install Specific Tidy3D Version Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Installs a specific version of Tidy3D, including pre-release versions, using pip. ```bash pip install tidy3d==x.y.z ``` -------------------------------- ### Migration Utility: Create and Run Batch Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/smatrix_migration.rst Uses the create_batch utility to manage a batch run, useful if you prefer to handle batch execution manually. This utility is temporary. ```python from tidy3d.plugins.smatrix.run import create_batch batch = create_batch(modeler=my_modeler) batch_data = batch.run() ``` -------------------------------- ### Configure Nexus with Automatic Settings Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Use the CLI to automatically configure Nexus, setting API, website, and S3 endpoints, and making Nexus the default profile. ```bash tidy3d configure --apikey YOUR_KEY \ --nexus-url http://your-server ``` -------------------------------- ### Install Pytest Coverage Plugin Source: https://github.com/flexcompute/tidy3d/blob/develop/tests/README.md Install the `pytest-cov` plugin to measure test coverage. This is a prerequisite for running coverage tests. ```bash pip install pytest-cov ``` -------------------------------- ### Create and Use ImpedanceCalculator Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/path_integrals.rst Shows how to initialize an ImpedanceCalculator using voltage and current integrals, and then compute the characteristic impedance (Z0) from mode data. It also illustrates how to retrieve voltage and current along with impedance. ```python # Create impedance calculator from voltage and current integrals Z_calculator = ImpedanceCalculator( voltage_integral=voltage_integral, current_integral=current_integral ) # Compute impedance: Z = V / I Z0 = Z_calculator.compute_impedance(mode_data) # Or get voltage, current, and impedance together Z, V, I = Z_calculator.compute_impedance( mode_data, return_voltage_and_current=True ) ``` -------------------------------- ### Setting up Mode Monitors and Sources for Multi-Simulation Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/invdes/README.md Configures mode monitors and creates independent sources for each output waveguide. This is a prerequisite for setting up multiple simulations in the inverse design process. ```python mnt_name_left = "mode" mnt_left = td.ModeMonitor( size=source.size, center=source.center, mode_spec=mode_spec, name=mnt_name_left, freqs=[freq0] ) srcs_right = [] for mnt in monitors_out: src_right = source.updated_copy( size=mnt.size, center=mnt.center, direction="-", ) srcs_right.append(src_right) ``` -------------------------------- ### Test Tidy3D Import after Installation Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/cli/readme.md Verify that Tidy3D and its components can be imported successfully after installation. This snippet checks for the presence of the 'click' module, which is a common dependency. ```python import tidy3d as td; import tidy3d.web as web; from tidy3d.plugins.mode import ModeSolver ``` -------------------------------- ### List available profiles Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/index.rst Use `config.profiles.list()` to discover available built-in and user-created profiles. ```python config.profiles.list() ``` -------------------------------- ### Perform Release Merge and Tag Source: https://github.com/flexcompute/tidy3d/wiki/2.--Developer-Guide Steps to prepare and release a new version. This involves merging 'develop' into 'main', tagging the release, and pushing the tag. ```bash git checkout main git merge develop git tag x.x.x git push origin x.x.x ``` -------------------------------- ### Pytest Name Matching Example Source: https://github.com/flexcompute/tidy3d/blob/develop/tests/README.md Demonstrates how pytest's `-k` flag matches test function names. It includes examples of functions that would be tested and one that would not. ```python def test_my_test(): # tested pass def test_xmy_testx(): # tested pass def test_test_other(): # not tested pass ``` -------------------------------- ### Initialize ImpedanceCalculator with Integration Paths Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/impedance_calculator.rst Use this snippet to create an ImpedanceCalculator instance. Define voltage and current integration paths using AxisAlignedVoltageIntegral and AxisAlignedCurrentIntegral respectively. The choice of integrals determines the impedance calculation method. ```python import tidy3d as td # Define voltage integration path voltage_integral = td.AxisAlignedVoltageIntegral( center=(0, 0, 0), size=(0, 0, 2), # Vertical line sign="+", extrapolate_to_endpoints=True, snap_path_to_grid=True ) # Define current integration contour current_integral = td.AxisAlignedCurrentIntegral( center=(0, 0, 0), size=(4, 2, 0), # Rectangular loop sign="+", snap_contour_to_grid=True ) # Create impedance calculator # Note: The impedance calculator can also accept "None" for either the "voltage_integral" or the "current_integral", # which determines the method for computing the impedance. This alternative method is detailed below. Z_calculator = td.ImpedanceCalculator( voltage_integral=voltage_integral, current_integral=current_integral ) ``` -------------------------------- ### Configure Tidy3D via uvx Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/ai/flex_agent.rst Configure Tidy3D using the uvx command-line tool. Alternatively, set the SIMCLOUD_APIKEY environment variable. ```bash uvx tidy3d configure ``` -------------------------------- ### Activate Tidy3D Conda Environment Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/install.rst Activate the newly created Conda environment before installing Tidy3D. ```bash mamba activate tidy3d_env ``` -------------------------------- ### Initialize AdamOptimizer Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/invdes/README.md Instantiate the AdamOptimizer with the inverse design object, number of steps, learning rate, and an optional cache file for saving optimization history. ```python optimizer = tdi.AdamOptimizer( design=design, num_steps=12, learning_rate=0.3, results_cache_fname="data/invdes_history.pkl", ) ``` -------------------------------- ### GridSpec Initialization Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/discretization/index.rst Demonstrates how to initialize a GridSpec object with different grid types for each spatial axis (x, y, z) and specifies the simulation wavelength. ```APIDOC ## GridSpec Initialization ### Description This example shows how to create a `GridSpec` object, which defines the spatial grid for an FDTD simulation. It illustrates using `AutoGrid` for the x-axis, `UniformGrid` for the y-axis, and `QuasiUniformGrid` for the z-axis, along with specifying the simulation's free-space wavelength. ### Method ```python my_grid_spec = GridSpec( grid_x = AutoGrid(min_steps_per_wvl=16), grid_y = UniformGrid(dl=0.1), grid_z = QuasiUniformGrid(dl=0.1), wavelength=1.55 ) ``` ### Parameters * `grid_x` (AutoGrid): Grid specification for the x-axis. * `grid_y` (UniformGrid): Grid specification for the y-axis. * `grid_z` (QuasiUniformGrid): Grid specification for the z-axis. * `wavelength` (float): The free-space wavelength of the simulation, required for `AutoGrid`. ``` -------------------------------- ### Get Radiation Metrics Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/radiation_scattering.rst Retrieve antenna metrics from a completed simulation using the get_antenna_metrics_data() method. ```python # Get radiation metrics my_antenna_metrics = my_tcm_data.get_antenna_metrics_data() # Get individual metrics my_directivity = my_antenna_metrics.directivity my_gain = my_antenna_metrics.gain my_radiation_efficiency = my_antenna_metrics.radiation_efficiency my_reflection_efficiency = my_antenna_metrics.reflection_efficiency my_realized_gain = my_antenna_metrics.realized_gain my_supplied_power = my_antenna_metrics.supplied_power my_radiated_power = my_antenna_metrics.radiated_power my_radiation_intensity = my_antenna_metrics.radiation_intensity my_axial_ratio = my_antenna_metrics.axial_ratio my_left_pol = my_antenna_metrics.left_polarization my_right_pol = my_antenna_metrics.right_polarization ``` -------------------------------- ### HeatChargeSimulation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/charge/simulation.rst Represents a heat charge simulation setup. This class is part of the tidy3d library for performing simulations. ```APIDOC ## HeatChargeSimulation ### Description Represents a heat charge simulation setup. This class is part of the tidy3d library for performing simulations. ### Class Signature ```python class tidy3d.HeatChargeSimulation ``` ### Parameters This class does not have explicitly documented parameters in the provided source. Refer to the library's documentation for detailed parameter information. ``` -------------------------------- ### Create a Structure Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Define a geometric structure with specific material properties. This example creates a box with a permittivity of 2.0. ```python # create structure - a box centered at 0, 0, 0 with a size of 1.5 micron and permittivity of 2 square = td.Structure( geometry=td.Box(center=(0, 0, 0), size=(1.5, 1.5, 1.5)), medium=td.Medium(permittivity=2.0) ) ``` -------------------------------- ### Initialize ImpedanceCalculator with Current Integral Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/impedance_calculator.rst Instantiate the ImpedanceCalculator using only the current integral. This is useful when voltage integral is not available or not needed for the calculation. ```python Z_calc_I = td.ImpedanceCalculator( voltage_integral=None, current_integral=current_integral ) # Computes: Z = 2*P / I^2 Z_from_I = Z_calc_I.compute_impedance(mode_data) ``` -------------------------------- ### ResonanceFinder Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/resonance.rst The ResonanceFinder class is part of the tidy3d plugins and is used for identifying resonant frequencies within a simulation setup. ```APIDOC ## ResonanceFinder ### Description Provides functionality to find resonant frequencies in a tidy3d simulation. ### Class `plugins.resonance.ResonanceFinder` ``` -------------------------------- ### Creating Boxes and Planes with Box Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/geometry.rst Demonstrates creating 3D boxes, 2D planes, and 1D lines using the Box primitive by specifying center and size, or by using bounds. Also shows how to extract planar surfaces. ```python # create a box by specifying center position and size my_box1 = Box(center=(-2,0,0), size=(1,2,1)) # create a box by specifying min/max bounds my_box2 = Box.from_bounds(rmin=(-1,-0.5,-1), rmax=(1, 0.5,1 )) # create a 2D plane by setting size to zero in the normal direction my_plane = Box(center=(0,0,-1), size=(5,5,0)) # create a 1D line by setting size to zero in two dimensions my_line = Box(center=(0,3,0), size=(5,0,0)) # get the 2D planar faces of a box quickly using the surfaces() method my_box_surfaces = Box.surfaces(center=(2,0,0), size=(1,1,1)) my_box_surfaces = my_box_surfaces[4:] # keep only the planes normal to z ``` -------------------------------- ### Get Field Data at Centers Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/data/README.md Retrieves field-like data evaluated at the Yee cell centers for a specified monitor. ```python sim_data.at_centers(monitor_name) ``` -------------------------------- ### Importing Dispersive Medium Models Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/mediums.rst Demonstrates how to import dispersive material models from local CSV files or remote URLs using FastDispersionFitter. ```APIDOC ## Importing Dispersive Medium Models ### Description Import dispersive material models from local files or URLs. ### Methods - `FastDispersionFitter.from_file(filepath, **kwargs)` - `FastDispersionFitter.from_url(url_file, **kwargs)` ### Parameters #### `from_file` - **filepath** (str) - Path to the local CSV file. - **skiprows** (int, optional) - Number of rows to skip at the beginning of the file. - **delimiter** (str, optional) - Delimiter used in the CSV file. #### `from_url` - **url_file** (str) - URL of the remote CSV file. - **delimiter** (str, optional) - Delimiter used in the CSV file. ### Request Example ```python # importing from a local file my_imported_medium = FastDispersionFitter.from_file("path/to/file.csv", skiprows=1, delimiter=",") # importing from a URL my_imported_medium_fromurl = FastDispersionFitter.from_url( url_file="https://refractiveindex.info/data_csv.php?datafile=database/data-nk/main/Ag/Johnson.yml", delimiter=",", ) ``` ``` -------------------------------- ### Get Lobe Characteristics Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/radiation_scattering.rst Access lobe characteristics such as direction, magnitude, and beamwidth for main and side lobes from the LobeMeasurer. ```python # Get lobe characteristics my_lobe_measures = my_lobes.lobe_measures my_main_lobe = my_lobes.main_lobe my_side_lobes = my_lobes.side_lobe ``` -------------------------------- ### Get Intensity Data Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/data/README.md Calculates and retrieves the intensity data for a field-like data object, evaluated at the Yee cell centers. ```python sim_data.get_intensity(monitor_name) ``` -------------------------------- ### Create a Scene Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/structure_and_scene.rst Instantiate a Scene with a list of structures, a background medium, and optionally specify plotting units. Scenes are useful for visualizing the physical layout. ```python # Create a scene using previously defined structures my_scene = Scene( structures = [my_structure_1, my_structure_2, my_structure_3], medium = my_background_medium, plot_length_units='mm', ) ``` -------------------------------- ### Core Workflow Functions Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/submit_simulations.rst Functions for the core simulation workflow: running, uploading, starting, monitoring, downloading, and loading simulations. ```APIDOC ## `web.run` ### Description Runs a simulation. ### Method APICall ## `web.upload` ### Description Uploads simulation data. ### Method APICall ## `web.start` ### Description Starts a simulation job. ### Method APICall ## `web.monitor` ### Description Monitors the status of a simulation. ### Method APICall ## `web.download` ### Description Downloads simulation results. ### Method APICall ## `web.load` ### Description Loads simulation data. ### Method APICall ## `web.api.asynchronous.run_async` ### Description Runs a simulation asynchronously. ### Method APICall ``` -------------------------------- ### Nexus Profile Configuration File Structure Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Example TOML structure for the Nexus profile configuration file, typically located at ~/.config/tidy3d/profiles/nexus.toml. ```toml [profile.nexus] api_endpoint = "http://your-server/tidy3d-api" website_endpoint = "http://your-server/tidy3d" s3_endpoint = "http://your-server:9000" s3_region = "us-east-1" ssl_verify = true caching = true ``` -------------------------------- ### Basic WavePort Creation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/microwave/ports/wave.rst Create a basic WavePort with automatic impedance calculation. This is useful for single-mode waveguide simulations. ```python my_wave_port_1 = WavePort( center=(0,0,0), size=(port_width, port_height, 0), name='My Wave Port 1', direction='+', # direction of signal mode_spec=MicrowaveModeSpec( num_modes=1, target_neff=1.5, impedance_specs=AutoImpedanceSpec() # automatic impedance calculation ), ) ``` -------------------------------- ### HeatSimulation Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/heat/simulation.rst Represents a heat simulation setup. Users can define the geometry, materials, sources, and boundary conditions for a heat transfer analysis. ```APIDOC ## Class: HeatSimulation ### Description Defines the parameters and configuration for a heat transfer simulation. This class is used to set up the physical problem, including geometry, material properties, heat sources, and boundary conditions. ### Usage ```python from tidy3d import HeatSimulation, Material, Box, Surface, Temperature # Define geometry and materials geometry = Box(size=(10, 10, 10), material=Material(thermal_conductivity=1.0)) # Define simulation parameters # (Specific parameters like time, solver settings, etc. would be detailed here if available in source) # Instantiate HeatSimulation sim = HeatSimulation(geometry=geometry, ...) # Further configuration and running the simulation would follow. ``` ### Parameters * **geometry** (Geometry) - Required - The geometric model for the simulation. * **materials** (list[Material]) - Optional - A list of materials to be used in the simulation. * **sources** (list[Source]) - Optional - A list of heat sources. * **boundary_conditions** (list[BoundaryCondition]) - Optional - A list of boundary conditions. * **solver_params** (SolverParams) - Optional - Parameters for the simulation solver. * **time_step** (float) - Optional - The time step for transient simulations. * **num_steps** (int) - Optional - The total number of time steps for transient simulations. ### Returns An instance of `HeatSimulation` configured with the provided parameters. ``` -------------------------------- ### Get Poynting Vector Data Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/data/README.md Retrieves the Poynting vector data for a field-like data object, evaluated at the Yee cell centers. ```python sim_data.get_poynting_vector(monitor_name) ``` -------------------------------- ### Evaluate an Expression Using Metrics as Variables Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/plugins/expressions/README.md Illustrates using metrics (like ModeAmp and ModePower) as variables within an expression. When evaluating, provide the SimulationData objects corresponding to each metric as keyword arguments. ```python from tidy3d.plugins.expressions import ModeAmp, ModePower # Define two named metrics mode_coeff1 = ModeAmp(name="mode_coeff1", monitor_name="monitor1", freqs=[1.0]) mode_power1 = ModePower(name="mode_power1", monitor_name="monitor2", freqs=[1.0]) # Create an expression using the metrics expr = mode_coeff1 + mode_power1 # Assume "data1" and "data2" are SimulationData objects obtained from different simulations result = expr(mode_coeff1=data1, mode_power1=data2) ``` -------------------------------- ### Regenerate Tidy3D Schemas with uv Source: https://github.com/flexcompute/tidy3d/blob/develop/schemas/README.md Use this command for stable output when regenerating schemas. Ensure you have uv installed and are using Python 3.11. ```bash uv run -p 3.11 python scripts/regenerate_schema.py ``` -------------------------------- ### New API: Cost Estimation via web.upload and web.estimate_cost Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/smatrix_migration.rst Illustrates the new cost estimation workflow, which involves uploading the modeler to the web API and then using web.estimate_cost and web.real_cost with the task ID. ```python task_id = web.upload(tcm) est_flex_credits = web.estimate_cost(task_id) # After the run is complete real_flex_credits = web.real_cost(task_id) ``` -------------------------------- ### Define Simulation Parameters Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/index.rst Set up global simulation parameters such as the base frequency. This frequency is used for defining sources and monitors. ```python # set up global parameters of simulation ( speed of light / wavelength in micron ) freq0 = td.C_0 / 0.75 ``` -------------------------------- ### ModeSource and ModeSpec Usage Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/mode/sources.rst Example demonstrating how to define a custom mode specification and create a mode source to inject a specific mode into the simulation. ```APIDOC ## ModeSource and ModeSpec ### Description This example shows how to configure the mode solver using `ModeSpec` and then define a `ModeSource` to inject a specific mode into the simulation. ### Usage ```python # custom mode specification tells the mode solver to search for # two modes around effective index = 1.5 my_mode_spec = ModeSpec(num_modes=2, target_neff=1.5) # custom mode source injects the first mode along the +x direction my_mode_source = ModeSource( size=(0,10,10), source_time=my_source_time, # Assuming my_source_time is defined elsewhere direction='+', mode_spec=my_mode_spec, mode_index=0, ) ``` ### Parameters #### ModeSpec Parameters - **num_modes** (int) - The number of modes to search for. - **target_neff** (float) - The target effective index around which to search for modes. #### ModeSource Parameters - **size** (tuple) - The dimensions of the source plane. - **source_time** (object) - The time profile of the source. - **direction** (str) - The direction of mode propagation ('+' or '-'). - **mode_spec** (ModeSpec) - The specification for the mode solver. - **mode_index** (int) - The index of the mode to inject (0-based). ``` -------------------------------- ### Configure API Key and Nexus URL Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/configuration/nexus.rst Configure your API key and Nexus URL simultaneously. Ensure you are validating against your specific Nexus endpoint. ```bash tidy3d configure --apikey YOUR_KEY \ --nexus-url http://your-nexus-server ``` -------------------------------- ### Reload Plugins in Claude Code Source: https://github.com/flexcompute/tidy3d/blob/develop/README.md If Claude Code is already running, use this command to reload plugins after installation to ensure the Tidy3D plugin is recognized. ```text /reload-plugins ``` -------------------------------- ### run Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/plugins/dispersion.rst Runs the dispersion fitting process, likely via a web service. ```APIDOC ## run (plugins.dispersion.web) ### Description Initiates the dispersion fitting process, potentially through a web API or service. This function is part of the web interface for dispersion fitting. ### Usage ```python from tidy3d.plugins.dispersion.web import run # Example usage (arguments would be specific to the web service) results = run(data=..., model_params=...) ``` ``` -------------------------------- ### EMESimulation.propagate Source: https://github.com/flexcompute/tidy3d/blob/develop/docs/api/eme/local_propagation.rst The convenience entry point for running EME end-to-end on a local machine. ```APIDOC ## EMESimulation.propagate ### Description Runs the EME simulation end-to-end on a local machine. ### Method `propagate` ### Parameters This method does not explicitly list parameters in the provided documentation. Refer to the `EMESimulation` class for potential initialization parameters. ### Response Returns the device S-matrix. Monitors are dropped. ``` -------------------------------- ### Get Active LocalCache Instance Source: https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/web/README.md Call `resolve_local_cache(use_cache=True)` to obtain the active `LocalCache` instance. This allows for programmatic interaction with the cache, such as listing its contents. ```python resolve_local_cache(use_cache=True) ```