Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MHKiT-Python v0.9.0 Support #149

Open
wants to merge 87 commits into
base: develop
Choose a base branch
from

Conversation

simmsa
Copy link
Contributor

@simmsa simmsa commented Dec 9, 2024

Support for MHKiT-Python 0.9.0

Major Changes

Version Compatibility Updates

  • Added support for MHKiT-Python 0.9.0
  • Dropped support for:
    • MHKiT-Python 0.8.2 and below
    • Python 3.8 and 3.9 (dropped in MHKiT-Python v0.9.0)
    • MATLAB R2021b and R2022a (Do not support Python 3.10 and above)
  • Updated compatibility tables in documentation here

Standardization of Type Conversions

This represents the initial implementation of standardized type conversion handling. Additional type
conversions will be implemented where necessary. Type conversion was heavily utilized in the wave
module to standardize xArray to Pandas output across different return types.

Note: At this time not all functions require changes to MHKiT-Python output type conversion. Only
functions that required standardized type conversion were changed in this PR

Currently implemented conversions:

  1. MATLAB struct spectra → DataFrame
  2. MHKiT Python outputs:
    • DataFrame
    • Series
    • Scalar
    • Array
    • Capture Length Matrix

Test Suite Modernization

  • Updated test suite for compatibility with latest MHKiT-Python version
  • Implemented standardized type conversion functions to resolve test failures

Outstanding Test Issues (assumeFail)

Note: Resolving these test failures is considered outside the scope of this PR as they require deeper investigation into underlying implementation differences between MHKiT-Python versions.
The following tests require further investigation and are currently marked as assumeFail:

  1. test_surface_elevation_seed

    • Issue: Surface elevation comparison mismatch
    • Analysis: Test assumes MHKiT-Python seed value of 123, which has been modified
    • Action Required: Verify current seed implementation in MHKiT-Python
  2. test_surface_elevation_phasing

    • Issue: Surface elevation comparison mismatch
    • Analysis: Inconsistent seed assumptions
    • Action Required: Review MHKiT-Python test implementation
  3. test_mler_coefficients

    • Issue: Mirror image output versus expected results
    • Action Required: Technical review with @hivanov-nrel regarding phase unwrapping in mler_coefficients
  4. test_bin_statistics

    • Issue: Inconsistent handling of 0 versus NaN values
    • Action Required: Consultation with @hivanov-nrel regarding specification for NaN versus zero handling

High level this is a byproduct of MHKiT-Python switching to xarray. I am
not exactly sure of the root cause, but the difference is that that
the modified MHKiT-Python functions return singular dimension DataFrames
that need to be accessed without using `.values`
@simmsa simmsa changed the base branch from master to develop December 9, 2024 20:14
simmsa added 25 commits December 9, 2024 13:18
Updating to newer versions of MATLAB and Python to see if any test
results change.
This attempts to fix:

```
 /opt/hostedtoolcache/MATLAB/2022.2.999/x64/interprocess/bin/glnxa64/pycli/../../../../sys/os/glnxa64/libstdc++.so.6:
      version `GLIBCXX_3.4.29' not found (required by
      /home/runner/miniconda3/envs/mhkit_conda_env/lib/python3.10/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-310-x86_64-linux-gnu.so)
```

By updating the MATLAB version.
Removed in MHKiT Python v0.8.0 and above
simmsa added 13 commits January 31, 2025 10:42
This seems to determine how stable MATLAB is and using an older version
is advantageous for compatibility. This increase is specifically for
Python 3.12.
One test fails with 1.11.4:

macos-13, Python 3.12, MATLAB R2024b

```
 ../Users/runner/miniconda3/envs/mhkit_conda_env/lib/python3.12/site-packages/scipy/__init__.py:132: UserWarning: A NumPy version >=1.21.6 and <1.28.0 is required for this version of SciPy (detected version 2.2.2)
    warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
```
Attempt to silence:

```
C:\Users\runneradmin\miniconda3\Lib\site-packages\conda\base\context.py:201: FutureWarning: Adding 'defaults' to channel list implicitly is deprecated and will be removed in 25.3.

To remove this warning, please choose a default channel explicitly with conda's regular configuration system, e.g. by adding 'defaults' to the list of channels:

  conda config --add channels defaults

For more information see https://docs.conda.io/projects/conda/en/stable/user-guide/configuration/use-condarc.html

  deprecated.topic(
```
@simmsa
Copy link
Contributor Author

simmsa commented Jan 31, 2025

Initial test failure summary:

Failure Summary (Windows cache population job):

   Name                                                                Failed  Incomplete  Reason(s)
  =================================================================================================================
   Loads_TestExtreme/test_mler_coefficients                              X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Loads_TestLoads/test_bin_statistics                                   X         X       Failed by assertion.
  -----------------------------------------------------------------------------------------------------------------
   Loads_TestLoads/test_damage_equivalent_loads                          X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Power_TestDevice/test_TCHD_sine_wave                                  X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestPerformance/test_capture_length                              X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestPerformance/test_capture_length_matrix                       X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestPerformance/test_power_matrix                                X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestPerformance/test_mean_annual_energy_production               X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestPerformance/test_power_performance_workflow                  X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_kfromw                                  X         X       Failed by assertion.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_moments                                 X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_metrics_HsP                             X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_metrics_AH                              X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_metrics_CDIP1                           X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_environmental_contour                             X       Filtered by assumption.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_plot_environmental_contour                        X       Filtered by assumption.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_plot_environmental_contour_multiyear              X       Filtered by assumption.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceMetrics/test_energy_flux_deep                        X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_pierson_moskowitz_spectrum             X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_surface_elevation_seed                 X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_surface_elevation_phasing              X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_surface_elevation_moments              X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_jonswap_spectrum                       X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/test_jonswap_spectrum_gamma                 X         X       Errored.
  -----------------------------------------------------------------------------------------------------------------
   Wave_TestResourceSpectrum/testSurfaceElevationMethod                  X         X       Errored.

Fails with this error:

```
Error using _cythonized_array_utils>init
      scipy.linalg._cythonized_array_utils (line 1)
      Python Error: ValueError: numpy.dtype size changed, may indicate binary
      incompatibility. Expected 96 from C header, got 88 from PyObject
```

Same test works on ubuntu. Likely related to scipy version
@simmsa
Copy link
Contributor Author

simmsa commented Feb 3, 2025

Current Windows Population Job Test Summary:


 Totals:
     179 Passed, 0 Failed, 5 Incomplete.
     635.3363 seconds testing time.
 
  Failure Summary:
  
       Name                                                                Failed  Incomplete  Reason(s)
      =================================================================================================================
       Loads_TestExtreme/test_mler_coefficients                                        X       Filtered by assumption.
      -----------------------------------------------------------------------------------------------------------------
       Loads_TestLoads/test_bin_statistics                                             X       Filtered by assumption.
      -----------------------------------------------------------------------------------------------------------------
       Wave_TestResourceMetrics/test_plot_environmental_contour_multiyear              X       Filtered by assumption.
      -----------------------------------------------------------------------------------------------------------------
       Wave_TestResourceSpectrum/test_surface_elevation_seed                           X       Filtered by assumption.
      -----------------------------------------------------------------------------------------------------------------
       Wave_TestResourceSpectrum/test_surface_elevation_phasing                        X       Filtered by assumption.

@simmsa simmsa marked this pull request as ready for review February 3, 2025 15:32
@simmsa simmsa requested review from rpauly18 and removed request for rpauly18 February 3, 2025 15:32
@simmsa
Copy link
Contributor Author

simmsa commented Feb 3, 2025

@rpauly18, this PR is ready for review.

This PR implements Python/Matlab type conversions that will unblock progress on the live scripts documentation (#110).

Failed tests for follow-up PR:

  1. test_mler_coefficients: Test reveals potential issue with RAO phase conversion
  2. test_bin_statistics: Output contains zeros where test expects NaN values
  3. test_surface_elevation_seed/phasing: Tests assume deterministic output with fixed seeds - needs updating per latest MHKiT-Python spec

Note: This PR touches multiple core modules requiring a merge commit. Recommend merging #151 first to avoid conflicts with the upcrossing module.

Copy link
Contributor

@rpauly18 rpauly18 left a comment

Choose a reason for hiding this comment

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

This looks good. Please make sure to document the unique install instructions (for Mac etc.) and update documentation accordingly

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