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

Upcoming Stan release removes old array syntax, new RStan needed #1084

Open
jgabry opened this issue Aug 25, 2023 · 51 comments
Open

Upcoming Stan release removes old array syntax, new RStan needed #1084

jgabry opened this issue Aug 25, 2023 · 51 comments

Comments

@jgabry
Copy link
Member

jgabry commented Aug 25, 2023

See https://discourse.mc-stan.org/t/cmdstan-stan-2-33-release-candidate/32531. This one actually removes the old array syntax, not just a deprecation warning.

@bgoodri @andrjohns @hsbadr Is RStan with new array syntax ready to be submitted to CRAN?

@jgabry
Copy link
Member Author

jgabry commented Aug 25, 2023

If it's ready, I would go ahead and submit it ASAP, I think CRAN is back from vacation

@andrjohns
Copy link
Contributor

@bgoodri if you're short on time or overloaded with other work, did you want to temporarily assign someone else as the maintainer for CRAN? Then we can get everything up to date ASAP and take some of the pressure off.

@hsbadr would be my first suggestion, but I'm also happy to take it if he doesn't have capacity either

@bgoodri
Copy link
Contributor

bgoodri commented Aug 30, 2023

I can do it. I have just been swamped this past month with a conference and teaching. We need to merge @andrjohns PR about switching the javascript library, but then 2.26.x is pretty much ready I think. Hopefully, we can go to 2.32.x almost immediately afterward because the error messages in 2.26 are not great and it doesn't have the tool to convert to the new array syntax. I imagine it will take a bit before all the packages actually convert to the new array syntax though.

@paul-buerkner
Copy link
Contributor

Thank you for all your efforts in getting this to work!

From the perspective of brms, not having the new array syntax in rstan is a huge problem since the latest cmdstan(r) will not support the old one anymore. So without the new rstan, I can either give up on one of the backends (which I won't), remove brms from CRAN (which I won't either), or add a lot of code that outputs new or old array syntax depending on the stan version that is used. The latter I would like to avoid as well, of course, since it complicates the whole code structure and would be a lot of additional work just for a temporary work around.

So from my side, I really cannot wait to have rstan 2.26+ on CRAN!

@andrjohns
Copy link
Contributor

@bgoodri Here are all the changes needed for rstan 2.26 on CRAN, I've run the reverse dependency checks and also checked on winbuilder and all passes.

StanHeaders needs one header updated for c++17: stan-dev/math@StanHeaders_2.26...rstan226-cran

Rstan changes (including the change from V8): StanHeaders_2.26...rstan-cran

Can you please either submit ASAP or let me know what else you need. The longer it takes to get rstan up, the worse it's going to be when dealing with the array syntax in packages

@jgabry
Copy link
Member Author

jgabry commented Aug 31, 2023

I've run the reverse dependency checks and also checked on winbuilder and all passes.

Thank you!

Can you please either submit ASAP or let me know what else you need. The longer it takes to get rstan up, the worse it's going to be when dealing with the array syntax in packages

Agree, let me know if there's anything I can do to help.

@hsbadr
Copy link
Member

hsbadr commented Aug 31, 2023

This one actually removes the old array syntax, not just a deprecation warning.

This is a big change that requires a lot of effort. The experimental tested the latest development branches of Math and Stan. Everything is ok except this change (see https://github.com/stan-dev/rstan/actions/runs/6012867756). We'll need to update all Stan code in RStan tests and ask all dependencies to adopt the new array syntax.

Rstan changes (including the change from V8): StanHeaders_2.26...rstan-cran

Do we need to rebase this for the experimental branch?

@hsbadr would be my first suggestion, but I'm also happy to take it if he doesn't have capacity either

Does CRAN allow for multiple maintainers? If so, I'd add more maintainers with @bgoodri to keep RStan alive.

@jgabry
Copy link
Member Author

jgabry commented Aug 31, 2023

This is a big change that requires a lot of effort. The experimental tested the latest development branches of Math and Stan. Everything is ok except this change (see https://github.com/stan-dev/rstan/actions/runs/6012867756). We'll need to update all Stan code in RStan tests and ask all dependencies to adopt the new array syntax.

Regarding the dependencies, if we give them a month or two of notice it should be OK for us to submit the update. So we could do 2.26 now and then 2.32 this fall. Especially if we give them a way to update their code (there's a tool to convert to the new syntax right?) then we satisfy CRAN's policy and we shouldn't keep holding up Stan development (plus having 2.26 out is going to lead to a lot of confusion if the error messages are messed up). I'm happy to help out with any of this (dependencies, test code), just let me know if/how I can be useful.

Do we need to rebase this for the experimental branch?

I'm not sure. @andrjohns @bgoodri?

Does CRAN allow for multiple maintainers? If so, I'd add more maintainers with @bgoodri to keep RStan alive.

No, unfortunately. They want a single point of contact.

Thanks again for all the work you've done to help with this already!

@bgoodri
Copy link
Contributor

bgoodri commented Sep 7, 2023

We are go for StanHeaders with the additional size -> math::size thing. I am a bit perplexed as to how StanHeaders 2.26.27 ultimately worked with survstan and all the other packages with rstan 2.21.x but not with rstan 2.26 but I can live without resolving that mystery.

The develop branch of rstan would satisfy the reverse dependency checks if not for that one error that is now fixed with StanHeaders. It is similar to @andrjohns branch, especially in the sense that it uses his QuickJSR package rather than V8 to handle the javascript stanc, which allows us to drop the old C++ stanc and parse both the old and the new array syntax. So, I think we should do a rstan 2.26 right after the StanHeaders 2.26.28 gets through CRAN so that @paul-buerkner just has to push a brms that requires rstan >= 2.26 .

I do want to get both StanHeaders and rstan up to Stan 2.32 right afterward, which as I understand it is basically the experimental branch. That release accepts the old array syntax but warns that it will be unsupported in 2.33. So, we will presumably have to prod a bunch of packages to run the canonicalizing tool on their Stan files.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 7, 2023

Uploading the new StanHeaders (that only changed one size to math::size) somehow broke the following rstantools-using packages on Fedora and M1:
Rglt
bmlm
eggCounts

It is the same error that we have encountered and fixed before, so I don't understand how it got triggered in these few circumstances by a StanHeaders that should not have affected their C++ code.

@paul-buerkner
Copy link
Contributor

I have no idea unfortunately. That said, it is totally okay for rstan to break some downstream packages with a major release. We desperately need rstan 2.26+ on CRAN asap (not just for brms but for many other reasons too). So if figuring out this error would caused another non-trivial delay to the release, I would strongly argue in favor of just allowing these packages to break and be fixed later (or removed from CRAN if no fixe it provided).

@bgoodri
Copy link
Contributor

bgoodri commented Sep 7, 2023

It is possible that we can go ahead with the rstan 2.26 because doing so would not make those three packages any "worse" as far as the CRAN checks are concerned than what they already are now that StanHeaders 2.26.28 already broke them. But it is still our responsibility to manage backwards incompatible changes on CRAN, even though in this case, it seems to be due to those packages using the older build process rather than letting rstantools do its thing to regenerate the C++ and the Makevars{.win} files when the package is compiled.

@andrjohns
Copy link
Contributor

@bgoodri those failures are because the packages aren't using rstantools to update their Makevars, and so are missing flags needed for compatibility with c++17 (the AUTO_PTR_ETC one)

They're easy fixes and I'll open PRs now, all safe to go ahead with the rstan submission

@andrjohns
Copy link
Contributor

@bgoodri PRs submitted:

  • bmlm
  • Rlgt
  • eggCounts: No public repo, emailed maintainer

I think that's plenty to satisfy CRAN, so please go ahead and submit rstan or let me know if you need anything else

@bgoodri
Copy link
Contributor

bgoodri commented Sep 7, 2023 via email

@harrelfe
Copy link

harrelfe commented Sep 7, 2023

I appreciate the work on this. I just updated my rmsb package to work with the new syntax for cmdstanr only to find that it breaks rstan so I've kind of stuck.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 7, 2023 via email

@bgoodri
Copy link
Contributor

bgoodri commented Sep 8, 2023

@paul-buerkner @harrelfe There is now a RStan on CRAN that accepts both array syntaxes. We will have to do a follow-up RStan based on 2.26 before we can do one based on 2.32 but that shouldn't affect you. It does seem possible to make a Stan program that is too complicated to be parsed by QuickJSR, so that might become an issue for some brms models.

@cdriveraus
Copy link

Thanks, nice to see this out. Not sure if I should start a new issue, but with the updated rstan / stanheaders, package building (with ctsem) has a substantial pause (30s maybe?) where it 'looks' like nothing is happening.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 8, 2023

That is presumably the parser parsing. I had the same thing with rstanarm (and then it failed). So, if it is just a compile time thing (in the case of ctsem and other packages that use rstantools), I am not too worried. The pause will be less noticeable with 2.32.

@cdriveraus
Copy link

happens with the rstantools configure script disabled too, and no compilation occurring, fyi.

@andrjohns
Copy link
Contributor

happens with the rstantools configure script disabled too, and no compilation occurring, fyi.

This is because we're using a less powerful javascript engine (quickjs instead of V8) which is more portable, but less performant.

There were significant optimisations in stanc3 after 2.26, so once we get StanHeaders 2.32 on CRAN then the parsing time should be ~3x faster

@harrelfe
Copy link

harrelfe commented Sep 8, 2023

I think I will modify the rmsb package to be for cmdstan and create a new package rmsbr whose sole content is rstan stanmodel objects that rmsb can use , primarily for Windows users. I'd like to avoid some future stan version conflicts. @paul-buerkner what do you think of that?

@andrjohns
Copy link
Contributor

I think I will modify the rmsb package to be for cmdstan and create a new package rmsbr whose sole content is rstan stanmodel objects that rmsb can use , primarily for Windows users. I'd like to avoid some future stan version conflicts. @paul-buerkner what do you think of that?

I don't think that's necessary (imo), we're past the difficult conflicts and updates so things should be fairly smooth from here on

@harrelfe
Copy link

harrelfe commented Sep 8, 2023

I think you're right @andrjohns but I wonder if I need to hedge my bets because of future changes to cmdstan.

@jgabry
Copy link
Member Author

jgabry commented Sep 8, 2023

@hsbadr would be my first suggestion, but I'm also happy to take it if he doesn't have capacity either

Speaking of @hsbadr, looks like still listed as a contributor. Should probably be an author going forward! (Noticed this when trying to update the website)

@bob-carpenter
Copy link

bob-carpenter commented Sep 8, 2023

Hi, @harrelfe. @andrjohns and @bgoodri have been working hard to make sure that things will be smoother after the 2.26 update (which just went live on CRAN) that things will be smoother.

To ensure there are no nasty surprises, I would strongly recommend updating your Stan code so that there are no deprecation warnings. We are going to start removing deprecated functionality. Also, we're not guaranteeing that binary models will be compatible version to version, just the Stan programs will still work if you recompile them. Other than that, there shouldn't be issues with backward compatibility going forward.

@bob-carpenter
Copy link

I wonder if I need to hedge my bets because of future changes to cmdstan.

Sorry---missed the later comment. The backward compatibility issues will be the same for cmdstan as for rstan and cmdstanr---we plan to remove deprecated functionality. Overall, we're recommending that people use cmdstanr when possible because it's not clear we'll keep upgrading RStan in the future given how much of a pain it is to get things on CRAN given lack of version dependency management and restrictive external unit test compatibility.

@hsbadr
Copy link
Member

hsbadr commented Sep 8, 2023

@WardBrian Can we temporarily get a patched version of stac3 JS v2.33.0 with soft deprecations (warnings instead of errors)?

@WardBrian
Copy link
Member

I think it wouldn’t be too much work to do so, I think we could cleanly revert the PR which made them errors (but the messages would say “2.33”, which might be confusing if it is 2.33)

Can I ask why this would be useful?

@hsbadr
Copy link
Member

hsbadr commented Sep 8, 2023

Can I ask why this would be useful?

It will allow us to quickly release RStan v2.33 and buy time to let the dependencies adopt the new syntax.

@WardBrian
Copy link
Member

I would prefer there to never be a version where users could write both the old array syntax and the new tuple types. They interact in weird and inconsistent ways (which was one of the primary motivations for the syntax change as I understand).

I think the plan of moving to 2.32 and pausing to allow packages to update is the best

@hsbadr
Copy link
Member

hsbadr commented Sep 8, 2023

I think the plan of moving to 2.32 and pausing to allow packages to update is the best

Sounds good to me.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 9, 2023

Does anyone know how to avoid this "significant" (in CRAN's eyes) warning message from clang that is now happening to @cdriveraus package with the 2.26ish Stan?

@cdriveraus
Copy link

cdriveraus commented Sep 9, 2023

@bgoodri this is fixed now, just some pointless code that crept in, and I believe there is the intention to automatically remove such lines in future stan versions...

stan-dev/stanc3#1357

@jgabry
Copy link
Member Author

jgabry commented Sep 9, 2023

I think the plan of moving to 2.32 and pausing to allow packages to update is the best

In addition to @WardBrian’s reason for not jumping straight to 2.33, another reason to prioritize 2.32 is that 2.33 has pathfinder, which still needs an RStan implementation and would delay things further. Doing an RStan 2.33 without the new featured method of Stan 2.33 would lead to a bunch of confusion, I think.

@harrelfe
Copy link

harrelfe commented Sep 9, 2023

The new rstan on CRAN worked perfectly for me after I updated Stan code syntax. I'll stick with the dual rstan cmdstan approach for now. I wish that there was a cmdstan binary for Windows users. A side issue: my submission of the rmsb package to CRAN was rejected because I didn't put where to find cmdstanr in the R package. I could not find documentation in the Writing R Extensions manual. Does anyone happen to know how to reference the cmdstanr location in an R package?

@jgabry
Copy link
Member Author

jgabry commented Sep 9, 2023

Does anyone happen to know how to reference the cmdstanr location in an R package?

There’s an Additional_repositories field you can specify in DESCRIPTION, e.g. in brms, which has cmdstanr in Suggests:

https://github.com/paul-buerkner/brms/blob/67ff198e30b96728dc8c66efae14d9a344d6d1ab/DESCRIPTION#L95-L96

@jgabry
Copy link
Member Author

jgabry commented Sep 9, 2023

Does anyone happen to know how to reference the cmdstanr location in an R package?

There’s an Additional_repositories field you can specify in DESCRIPTION, e.g. in brms, which has cmdstanr in Suggests:

https://github.com/paul-buerkner/brms/blob/67ff198e30b96728dc8c66efae14d9a344d6d1ab/DESCRIPTION#L95-L96

This might also be of interest: https://discourse.mc-stan.org/t/instantiate-pre-compiled-cmdstan-models-in-r-packages/32191

@andrjohns
Copy link
Contributor

@hsbadr Now that 2.26 is in develop, can you prepare a PR for merging in experimental? Once @bgoodri is happy for that to go in and it's merged, then can you make branch/tag for 2.32?

That will make it a bit easier to start prepping for the 2.32 submission

@andrjohns
Copy link
Contributor

@bgoodri @hsbadr @jgabry

Something that's also going to be a little tricky, rstan::stanc() is also currently not configured to check/return warnings (array syntax, deprecations, etc.) from stanc:

if (inherits(model_cppcode, "try-error")) {

It only checks for errors. There needs to be an additional block:

else if (length(model_cppcode$warnings)) {
    model_cppcode$status <- FALSE
    warning(paste(model_cppcode$warnings, collapse = "\n"))
  }

However, this would currently cause downstream dependencies to start failing R CMD CHECK because of the warning. So the options are:

  • Print the warning without using warning() (if there's a way to do that doesn't cause R CMD CHECK flags
  • Suppress any warnings when called in rstantools::rstan_config()
  • Ignore this until downstream won't fail (not really an option, imo)

Any preferences?

@hsbadr
Copy link
Member

hsbadr commented Sep 10, 2023

can you prepare a PR for merging in experimental?

It's ready to get merged into develop, and I've fixed the deprecated array syntax with stanc3 JS v2.33.

I think we should merge it as it's the real development branch, and then we create a branch of it for each release and tag it. It seems that we target v2.32 for now. That would require resetting the Stan submodule to v2.32.2 tag, shipping stanc3 JS v2.32.2, and updating the version number.

@bgoodri Are you ok with this? If so, I can create a PR to merge the experimental branch (or you can just merge it right away), and then I create v2.23.2 branch from the updated develop branch.

@andrjohns
Copy link
Contributor

@hsbadr quick FYI on the experimental branch, I just installed the StanHeaders binaries from the latest actions run, and it looks like the Math submodule is missing the patches from this Math PR: stan-dev/math#2892 so the installation is failing with Clang 16

@hsbadr
Copy link
Member

hsbadr commented Sep 10, 2023

Alternatively, updating the reverse dependencies with the new array syntax should be an easy task (though, it might cause delays depending the response of the maintainers). If we create PRs for this, we can submit v2.33 to CRAN after a few weeks. This will let CRAN as well force the maintainers to update their packages with the new array syntax.

@andrjohns
Copy link
Contributor

Alternatively, updating the reverse dependencies with the new array syntax should be an easy task (though, it might cause delays depending the response of the maintainers). If we create PRs for this, we can submit v2.33 to CRAN after a few weeks. This will let CRAN as well force the maintainers to update their packages with the new array syntax.

Yep I'm already in progress with this. I've got PR's open with about half of the downstream dependencies. I'll be opening an issue summarising the progress once I've identified all of the downstream failures

@hsbadr
Copy link
Member

hsbadr commented Sep 10, 2023

@hsbadr quick FYI on the experimental branch, I just installed the StanHeaders binaries from the latest actions run, and it looks like the Math submodule is missing the patches from this Math PR: stan-dev/math#2892 so the installation is failing with Clang 16

It uses the current develop branch of Stan. I'll look into it.

@hsbadr
Copy link
Member

hsbadr commented Sep 10, 2023

@hsbadr quick FYI on the experimental branch, I just installed the StanHeaders binaries from the latest actions run, and it looks like the Math submodule is missing the patches from this Math PR: stan-dev/math#2892 so the installation is failing with Clang 16

Fixed. It was a leftover from merging the develop (uses StanHeaders_2.26) branch into experimental.

@jgabry
Copy link
Member Author

jgabry commented Sep 10, 2023

thanks for working on this!

  • Print the warning without using warning() (if there's a way to do that doesn't cause R CMD CHECK flags

If we want to go this route, I think message() instead of warning() could probably get around CRAN issues. that wouldn’t convey the same sense of urgency as a warning but we could use strong language in the message I guess.

@jgabry
Copy link
Member Author

jgabry commented Nov 9, 2023

@bgoodri @hsbadr @andrjohns What's the current status of StanHeaders? RStan is at 2.32 but StanHeaders is at 2.26 and I think that's starting to lead to understandable confusion about which features are available in RStan (it seems reasonable to expect 2.32 features). For example, see this forum post from @cdriveraus about complex numbers: https://discourse.mc-stan.org/t/complex-custom-functions-not-working/33268.

If I recall correctly StanHeaders 2.32 was held up by CRAN for some reason, but not sure if that's accurate. Anything I can do to help?

@bgoodri
Copy link
Contributor

bgoodri commented Nov 10, 2023

The status of StanHeaders 2.32 (with the stanc.js from 2.32) is blocked by ConnorDonegan/geostan#17

@jgabry
Copy link
Member Author

jgabry commented Nov 10, 2023

Oh ok, thanks. Have you seen the most recent message there? ConnorDonegan/geostan#17 (comment)

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

No branches or pull requests

9 participants