Skip to content

Finalize and Test optiland.environment Subpackage#342

Merged
HarrisonKramer merged 26 commits intomasterfrom
feat/multi-air-models
Sep 30, 2025
Merged

Finalize and Test optiland.environment Subpackage#342
HarrisonKramer merged 26 commits intomasterfrom
feat/multi-air-models

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This commit finalizes the implementation and testing of the optiland.environment subpackage.

The work includes:

  • Model Verification: All four refractive index models (Ciddor, Edlén, Birch & Downs, Kohlrausch) were verified against external authoritative sources, including the RefractiveIndex.INFO reference script, NIST documentation, and Zemax OpticStudio formulas. Implementations were corrected to align with these standards.
  • Comprehensive Testing: The test suite for the subpackage was thoroughly reviewed and updated. Tests now use verified reference values, and new tests were added to cover edge cases and ensure 100% test coverage.
  • Improved Documentation: All modules and functions now have comprehensive Google-style docstrings, including usage examples, clear explanations of the models, and references to the authoritative sources used for implementation and validation.
  • Code Quality: The entire subpackage was linted and formatted with ruff to ensure it adheres to project quality standards. Input validation was also added to improve the robustness of the model functions.

PR created automatically by Jules for task 7961041228231751633

google-labs-jules bot and others added 24 commits July 1, 2025 19:55
This commit expands the `optiland.environment` subpackage by adding
implementations for three additional air refractive index models:

1.  **Kohlrausch (Simplified)**: A basic model using a Cauchy-like
    dispersion formula and P,T scaling. Primarily for dry air.
2.  **Edlén (1966)**: Implements the well-known Edlén formulation,
    including dispersion, P,T correction, and water vapor term.
    Assumes 300ppm CO2.
3.  **Birch & Downs (1993/1994)**: Implements the updated Edlén-style
    equations, including CO2 concentration as an input and a more
    refined water vapor term.

Key changes:
- Added `kohlrausch.py`, `edlen.py`, `birch_downs.py` modules with
  model implementations.
- Updated `air_index.py` to dispatch to these new models and updated
  its documentation.
- Updated `optiland.environment.__init__.py` to export the new model
  functions.
- Added pytest-style unit tests for each new model in
  `tests/environment/` (`test_kohlrausch.py`, `test_edlen.py`,
  `test_birch_downs.py`), including validation against reference values
  where available.

All new code includes Google-style docstrings, adheres to an 88-character
line limit, and follows best practices for clarity and modularity.
- Updated the __init__.py file to reflect the new structure of the environmental modeling package, changing the module description and reorganizing imports.
- Moved model imports to a new models subpackage for better organization.
- Deleted the old birch_downs.py file and created a new birch_downs.py in the models subpackage with updated documentation and implementation.
- Added new models for Ciddor, Edlén, and Kohlrausch, each with their respective implementations and documentation.
- Ensured all models utilize the EnvironmentalConditions class for parameter handling.
… rename kohlrausch_air_refractive_index function for clarity
…nd compatibility

This commit introduces comprehensive pytest-based unit tests for the
optiland.environment subpackage, including models (Birch-Downs, Ciddor,
Edlen, Kohlrausch), the EnvironmentalConditions dataclass, and the
refractive_index_air dispatcher.

Key changes:
- Rewrote existing tests for all environment models to use pytest,
  current model constants, and best practices.
- Added tests for helper functions within models.
- Converted unittest-based tests (test_ciddor.py) to pytest.
- Created new test files: test_conditions.py, test_air_index.py.
- Updated environment model implementations to use `optiland.backend as be`
  for mathematical operations, enabling backend-agnostic testing.
- Integrated the `set_test_backend` fixture across all relevant test
  files to allow testing with both numpy and torch backends.
- Implemented temporary workarounds in `tests/conftest.py` and
  `optiland/environment/__init__.py` to handle a persistent
  `ModuleNotFoundError` for `numpy` in the test environment, allowing
  some non-backend-dependent components to be tested/imported.

Note on Test Execution:
Due to a persistent `ModuleNotFoundError: No module named 'numpy'` in the
current CI/test environment, many of the newly added/rewritten tests that
depend on `optiland.backend` (i.e., all model tests and air_index tests)
will fail during test collection. The tests themselves are structured
correctly and are expected to pass once the numpy/backend visibility issue
in the environment is resolved. The `test_conditions.py` tests, which
do not depend on the backend, are passing.
This commit finalizes the implementation and testing of the `optiland.environment` subpackage.

The work includes:
- **Model Verification:** All four refractive index models (Ciddor, Edlén, Birch & Downs, Kohlrausch) were verified against external authoritative sources, including the `RefractiveIndex.INFO` reference script, NIST documentation, and Zemax OpticStudio formulas. Implementations were corrected to align with these standards.
- **Comprehensive Testing:** The test suite for the subpackage was thoroughly reviewed and updated. Tests now use verified reference values, and new tests were added to cover edge cases and ensure 100% test coverage.
- **Improved Documentation:** All modules and functions now have comprehensive Google-style docstrings, including usage examples, clear explanations of the models, and references to the authoritative sources used for implementation and validation.
- **Code Quality:** The entire subpackage was linted and formatted with `ruff` to ensure it adheres to project quality standards. Input validation was also added to improve the robustness of the model functions.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

@HarrisonKramer HarrisonKramer marked this pull request as ready for review September 30, 2025 09:05
Copilot AI review requested due to automatic review settings September 30, 2025 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR finalizes the implementation and testing of the optiland.environment subpackage, which provides comprehensive air refractive index calculations using four established models: Ciddor, Edlén, Birch & Downs, and Kohlrausch. The implementation includes verified reference values, comprehensive test coverage, improved documentation, and code quality improvements following the project's standards.

Key Changes

  • Complete implementation of four refractive index models with verified formulas
  • Comprehensive test suite achieving 100% coverage with verified reference values
  • Enhanced documentation with Google-style docstrings and authoritative references

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
optiland/environment/__init__.py Package initialization with unified exports and documentation
optiland/environment/air_index.py Main dispatcher function for selecting refractive index models
optiland/environment/conditions.py Dataclass for environmental parameters
optiland/environment/models/birch_downs.py Birch & Downs (1994) model implementation
optiland/environment/models/ciddor.py Ciddor (1996) model implementation with BIPM-91 equation
optiland/environment/models/edlen.py Edlén (1966) model with NIST temperature correction
optiland/environment/models/kohlrausch.py Kohlrausch model as used in Zemax OpticStudio
tests/environment/__init__.py Test package initialization
tests/environment/test_air_index.py Tests for the main dispatcher function
tests/environment/test_birch_downs.py Comprehensive tests for Birch & Downs model
tests/environment/test_ciddor.py Comprehensive tests for Ciddor model
tests/environment/test_conditions.py Tests for EnvironmentalConditions dataclass
tests/environment/test_edlen.py Comprehensive tests for Edlén model
tests/environment/test_kohlrausch.py Comprehensive tests for Kohlrausch model

This commit finalizes the implementation and testing of the `optiland.environment` subpackage.

The work includes:
- **Model Verification:** All four refractive index models (Ciddor, Edlén, Birch & Downs, Kohlrausch) were verified against external authoritative sources, including the `RefractiveIndex.INFO` reference script, NIST documentation, and Zemax OpticStudio formulas. Implementations were corrected to align with these standards.
- **Comprehensive Testing:** The test suite for the subpackage was thoroughly reviewed and updated. Tests now use verified reference values, and new tests were added to cover edge cases and ensure 100% test coverage.
- **Improved Documentation:** All modules and functions now have comprehensive Google-style docstrings, including usage examples, clear explanations of the models, and references to the authoritative sources used for implementation and validation.
- **Code Quality:** The entire subpackage was linted and formatted with `ruff` to ensure it adheres to project quality standards. Input validation was also added to improve the robustness of the model functions.
This commit addresses two issues that caused test failures when using the torch backend:

1.  A `TypeError` in the `_calculate_saturation_vapor_pressure` function within the Ciddor model was resolved. The `torch.where` function was being called with a boolean condition instead of a tensor, which has been corrected.
2.  A `RuntimeError` in the test suite caused by `pytest.approx` attempting to convert a `torch` tensor with an active gradient to a NumPy array has been fixed. The tensors are now detached before comparison.

All tests in `tests/environment` now pass for both the numpy and torch backends.
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 97.75281% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/environment/test_air_index.py 75.75% 16 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #342      +/-   ##
==========================================
+ Coverage   93.40%   93.65%   +0.24%     
==========================================
  Files         219      232      +13     
  Lines       11998    12710     +712     
==========================================
+ Hits        11207    11903     +696     
- Misses        791      807      +16     
Files with missing lines Coverage Δ
optiland/environment/__init__.py 100.00% <100.00%> (ø)
optiland/environment/air_index.py 100.00% <100.00%> (ø)
optiland/environment/conditions.py 100.00% <100.00%> (ø)
optiland/environment/models/birch_downs.py 100.00% <100.00%> (ø)
optiland/environment/models/ciddor.py 100.00% <100.00%> (ø)
optiland/environment/models/edlen.py 100.00% <100.00%> (ø)
optiland/environment/models/kohlrausch.py 100.00% <100.00%> (ø)
tests/environment/test_birch_downs.py 100.00% <100.00%> (ø)
tests/environment/test_ciddor.py 100.00% <100.00%> (ø)
tests/environment/test_conditions.py 100.00% <100.00%> (ø)
... and 3 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HarrisonKramer HarrisonKramer merged commit 0c778a2 into master Sep 30, 2025
11 checks passed
@HarrisonKramer HarrisonKramer deleted the feat/multi-air-models branch September 30, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants