pvlib-python icon indicating copy to clipboard operation
pvlib-python copied to clipboard

WIP: Convert between CEC and PVsyst single diode models

Open cwhanse opened this issue 1 year ago • 13 comments

  • [x] Closes #1935
  • [x] I am familiar with the contributing guidelines
  • [x] Tests added
  • [ ] Updates entries in docs/sphinx/source/reference for API changes.
  • [ ] Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • [ ] New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • [ ] Pull request is nearly complete and ready for detailed review.
  • [ ] Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

Primary reference is in review. Feedback on function naming and signature is welcome.

cwhanse avatar Sep 16 '24 18:09 cwhanse

Feedback on function naming and signature is welcome.

I guess one might discuss whether you are converting models or sets of parameters.

adriesse avatar Sep 17 '24 09:09 adriesse

Test failure for ubuntu-latest, 3.8, conda, -min is because that environment installs scipy=1.6.0, which doesn't allow for constraints when using Nelder-Mead, so the optimizer gets a different, unsatisfactory, solution.

cwhanse avatar Sep 19 '24 21:09 cwhanse

I guess one might discuss whether you are converting models or sets of parameters.

@adriesse , do you have any proposal in mind? For example, cec_params_to_pvsyst, params[_from]_pvsyst_to_cec [params_pvsyst2cec]. I don't really have a strong preference on wording.

scipy=1.6.0, which doesn't allow for constraints when using Nelder-Mead

scipy=1.7.0 is the first version to support it, and is also supported in Py3.9 (taking into account upcoming drop of Py3.8 support). I would edit this requirement for future >=Py3.9 release (#2213).

Source of scipy docs on nelder-mead; scipy 1.6.3 bumps to 1.7.0:

  • 1.6.3 https://docs.scipy.org/doc/scipy-1.6.3/reference/optimize.minimize-neldermead.html?highlight=nelder%20mead
  • 1.7.0 https://docs.scipy.org/doc/scipy-1.7.0/reference/reference/optimize.minimize-neldermead.html

echedey-ls avatar Sep 19 '24 21:09 echedey-ls

Is the simplex solver required? Why not try Powell instead?

mikofski avatar Sep 20 '24 06:09 mikofski

Is the simplex solver required? Why not try Powell instead?

@leliadeville

cwhanse avatar Sep 20 '24 15:09 cwhanse

Is the simplex solver required? Why not try Powell instead?

@mikofski I used Nelder-Mead to develop and check the algorithm, but I think the optimization method would be good to have as a parameter.

leliadeville avatar Sep 20 '24 15:09 leliadeville

Any particular reason for choosing Simplex? Good idea to make method a parameter. I would be curious to see how other methods like Powell compare. My experience is that the system of equations is stiff and requires some transformation to improve the condition. An excellent primer for selecting methods is https://gael-varoquaux.info/scipy-lecture-notes/advanced/mathematical_optimization/index.html#choosing-a-method

mikofski avatar Sep 21 '24 04:09 mikofski

For context, here's the submitted paper. The main point is determining that optimization is preferred over two other techniques (functions currently in pvlib, and an approach that equates quantities that should have the same values at the reference condition.) The optimization could certainly be tuned and improved.

sdm_translation_submitted.pdf

cwhanse avatar Sep 21 '24 14:09 cwhanse

The main point is determining that optimization is preferred …

I agree 💯. I wrote a blog on using implicit methods to solve SDM system of equations with several gists comparing using convex optimization after transforming the variables to improve the condition of the Jacobian to explicit methods using Bishop’s method. Because the equations are differential I used the SciPy wrapper around the MINPACK FORTRAN HYBRDJ solver but other solvers might be more efficient.

mikofski avatar Sep 21 '24 15:09 mikofski

I understand now, after reading the paper. This is a method of directly obtaining parameters without generating an IEC-61853 matrix as the go between first. Very clever! So the minimization method of the objective function is secondary, and there are no variables to transform. Thanks for patiently explaining. Great job @leliadeville

mikofski avatar Sep 21 '24 15:09 mikofski

This is a method of directly obtaining parameters without generating an IEC-61853 matrix as the go between first.

I may be misunderstanding, but generating the IEC-61853 matrix data for the source model is the first step. The target model's parameters are found by fitting the target model to the IEC-61853 matrix data.

cwhanse avatar Sep 21 '24 16:09 cwhanse

You are right. Sorry I misread. Looking again, this does solve each model independently from the matrix. Honestly I’m not sure what I was thinking before.

However, I think it would be interesting to see by comparison a method that does use the Jacobian, similar to what I discussed in the gist linked above or in PVMismatch gen_coeffs(), the two approaches differ by single and two diode model, but both transform the variables into either parabolic or log space and then use a gradient search method to solve the convex optimization problem. The method may suffer from poor initial guess but typically converges faster than simplex. Anyway, there is no publication, so I apologize for ranting. Thanks.

mikofski avatar Sep 21 '24 18:09 mikofski

I guess one might discuss whether you are converting models or sets of parameters.

@adriesse , do you have any proposal in mind? For example, cec_params_to_pvsyst, params[_from]_pvsyst_to_cec [params_pvsyst2cec]. I don't really have a strong preference on wording.

I may have just been referring to the title of the PR. No need to overload the function names.

adriesse avatar Apr 11 '25 07:04 adriesse

@pvlib/pvlib-maintainer I am perplexed by the test failure. Test passes when I run it locally, and the results compare favorably when I look at the numbers.

Is there some pvlib setting that may be affecting the isclose function?

cwhanse avatar Oct 06 '25 16:10 cwhanse

I am perplexed by the test failure. Test passes when I run it locally, and the results compare favorably when I look at the numbers.

Is there some pvlib setting that may be affecting the isclose function?

@cwhanse, I can reproduce it on Windows x64, Python 3.11.8, in a venv, and Numpy version:

>>> from importlib.metadata import version
>>> version("numpy")
'2.1.3'

Hope that helps with your setup. Sry for not getting a deeper look at it, not enough time lately to FOSS.

echedey-ls avatar Oct 06 '25 18:10 echedey-ls

@echedey-ls thanks, after a little more investigation I figured it was configuration dependent. There's one parameter being estimated that's very sensitive to what must be round-off level differences.

cwhanse avatar Oct 06 '25 19:10 cwhanse

Closing due to a decision that this algorithm is not sufficiently mature. We found that convergence is sensitive to initial condition and haven't found a method to overcome the sensitive dependence.

cwhanse avatar Dec 09 '25 18:12 cwhanse