# SciPy: "there is interest in adopting this (PRIMA) implementation, but little appetite for taking on more Fortran code"

**URL:** <https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821>\
**Category:** Uncategorized\
**Created:** [May 18, 2023, 9:47am UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821 "2023-05-18T09:47:38Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![egio](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@egio](https://fortran-lang.discourse.group/u/egio)\
**Post date:** [May 19, 2023, 7:56am UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/21 "2023-05-19T07:56:54Z")

</div>

There is another crucial point if one want to integrate it in **scipy**.  
It should never fail due to stack exhaustion, as you well know.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@ChrisRackauckas](https://fortran-lang.discourse.group/u/ChrisRackauckas)\
**Post date:** [May 19, 2023, 6:31pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/22 "2023-05-19T18:31:32Z")

</div>

> [@zaikunzhang](#):
>
> There is a discussion about this topic on the Front Page of Hacker News:
> 
> (Of course, its position is falling with time going. It is about 20 at the time of writing. )
> 
> This is the second time that PRIMA appears as a front-page story within a week (indeed, three days), [. Interestingly and encouragingly, **many comments there show that there is still quite strong support for Fortran in the technology community.**

Yeah I saw this pop up and was confused. I develop the Julia SciML organization [https://sciml.ai/](https://sciml.ai/) and we’d be more than happy to work with you to get wrappers for PRIMA into Optimization.jl’s general interface.

> **[Optimization.jl: A Unified Optimization Package · Optimization.jl](https://docs.sciml.ai/Optimization/stable/)**
>
> Documentation for Optimization.jl.

Please get in touch and we can figure out how to set this all up. I’d be curious to try this out and do some benchmarks against nlopt methods.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [May 20, 2023, 1:38pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/23 "2023-05-20T13:38:48Z")

</div>

I’ll have to censor myself, because a proper answer to SciPy’s maintainer statement, “we’re already working to get rid of it”, can only be offensive and far from being polite. Therefore I will just express my humble opinion that “Sci” and “Py” don’t go together, so “SciPy” can only be interpreted as a joke. And yes, I am aware it is popular, despite the fact it is… what it is (self-censoring here).

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [May 20, 2023, 1:55pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/24 "2023-05-20T13:55:20Z")

</div>

Hi @Pap it would be shameful to shame SciPy’s work, honestly their library has been an excellent work to enable new scientist-in-the-making to discover complex algorithms in a Top-down approach which has indeed empowered a lot of people!!

I have used SciPy for years to learn or to benchmark many codes before pushing the performance barriers in Fortran…

There are many extremally well known python APIs out there using SciPy behind the curtains.

We should work much more closely with them, it would be extremally beneficial for both communities!!

And they seem to be indeed very open to the guidance we could provided to move forward: please follow the latest comments here : [ENH: The Fortran 77 implementation of COBYLA is buggy and challenging to maintain. Switch to the PRIMA implementation? · Issue #18118 · scipy/scipy · GitHub](https://github.com/scipy/scipy/issues/18118#issuecomment-1555912477)

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [May 20, 2023, 2:10pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/25 "2023-05-20T14:10:19Z")

</div>

> [@hkvzjal](#):
>
> We should work much more closely with them, it would be extremally beneficial for both communities!!

I would probably agree, if they didn’t say that they are just trying to get rid of Fortran, so everything new they might add should not be in Fortran. They even consider using… f2c as a solution, to convert the code to “holy” C (and I don’t mean HolyC by T.A. Davis). I honestly don’t see any room for cooperating.

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [May 20, 2023, 2:26pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/26 "2023-05-20T14:26:57Z")

</div>

The answer from one of the maintainers after a proposal on a Fortran wrapper to avoid f2py…

> That wrapper code looks pretty reasonable and is a lot easier to understand than `f2py` imho. I think we could give that a try.  
> (…)  
> Yes you are right. My question was what _not_ using `f2py` would mean - but `bind(c)` takes care of all that, and is way better than the unreadable generated code that `f2py` emits to deal with name mangling.

Please take the time to fully read! you could be surprised what a small amount of kind sharing and help can do.

---

<div class="post-metadata">

**Author:** ![lmiq](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lmiq/32/555_2.png) [@lmiq](https://fortran-lang.discourse.group/u/lmiq)\
**Post date:** [May 22, 2023, 12:32pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/27 "2023-05-22T12:32:21Z")

</div>

It would be very nice if, later, you write a post here or somewhere else explaining what was the best interfacing solution you arrived at with them. Having that clearly documented will be very helpful for others developing Fortran routines to interface with python or C.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [February 2, 2024, 8:50pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/28 "2024-02-02T20:50:54Z")

</div>

@zaikunzhang [tweeted](https://twitter.com/LibPrima/status/1753492413988180172) that

> COBYQA by Tom M. Ragonneau and Zaikun Zhang is becoming the next derivative-free (a.k.a. zeroth-order / gradient-free) optimization solver in SciPy.

Congratulations, and thanks for showing that it is possible to get modern Fortran into non-Fortran-specific libraries, with some persistence.

> <https://github.com/scipy/scipy/pull/19994>
>
> \<!-- 
> Thanks for contributing a pull request! Please ensure that
> your PR satis…fies the checklist before submitting:
> http://scipy.github.io/devdocs/dev/contributor/development\_workflow.html#checklist-before-submitting-a-pr
> 
> Also, please name and describe your PR as you would write a
> commit message:
> http://scipy.github.io/devdocs/dev/contributor/development\_workflow.html#writing-the-commit-message
> 
> Depending on your changes, you can skip CI operations and save time and energy: 
> http://scipy.github.io/devdocs/dev/contributor/continuous\_integration.html#skipping
> 
> Note that we are a team of volunteers; we appreciate your
> patience during the review process.
> 
> Again, thanks for contributing!
> \--\>
> 
> \#### Reference issue
> 
> Closes #19918.
> 
> \#### What does this implement/fix?
> 
> This PR adds the COBYQA method to the \`scipy.optimize\` module.
> 
> \#### Additional information

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [February 2, 2024, 9:03pm UTC](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821/29 "2024-02-02T21:03:56Z")

</div>

Thank you @Beliavsky !

However, [COBYQA](http://cobyqa.com) is not [PRIMA](http://libprima.net), although both are derivative-free (a.k.a. zeroth-order/gradient-free) optimization (DFO) packages.

COBYQA is a new algorithm, developed by Tom M. Ragonneau (my former Ph.D. student) and Zaikun Zhang (me) as **part** of [Tom’s Ph.D. thesis](https://theses.lib.polyu.edu.hk/handle/200/12294) during 2019–2022. It is coded in Python (with Cython). Tom did all the coding.

PRIMA is a package that I have been working on for modernizing Powell’s DFO solvers. Powell coded them in F77, and I have reimplemented them in modern Fortran during 2020-present.

PRIMA is also being integrated into SciPy:

- [ENH: The Fortran 77 implementation of COBYLA is buggy and challenging to maintain. Switch to the PRIMA implementation? · Issue #18118 · scipy/scipy · GitHub](https://github.com/scipy/scipy/issues/18118)
- [RFC: Tracking progress to integrate with SciPy · Issue #112 · libprima/prima · GitHub](https://github.com/libprima/prima/issues/112)

However, it needs much more work due to the multiple languages involved. The community (including the SciPy maintainers) is providing a lot of help, but more is needed. I am completely ignorant about Python, so I have to rely on community help.

I hope the success of COBYQA will help us to promote PRIMA in multiple ways.

Thank you.

[Previous page](https://fortran-lang.discourse.group/t/scipy-there-is-interest-in-adopting-this-prima-implementation-but-little-appetite-for-taking-on-more-fortran-code/5821.md?page=1)
