Coder Social home page Coder Social logo

Comments (3)

marianklose avatar marianklose commented on May 12, 2024 1

Okay, so apparently following the full instructions from stan-dev/cmdstan#1064 did the job for me.

To run CmdStan with Rtools42 you need to do the following (This assumes Rtools42:

  1. Add C:\rtools42\usr\bin and C:\rtools42\ucrt64\bin to the PATH
  2. Run pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc in a freshly opened Powershell
  3. Add the following two lines to the make/local:

CXXFLAGS += -Wno-nonnull
TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00

And that should do it.

Explanation of the steps:

The second step installs ucrt64 versions of mingw32-make and g++ (11.2) that are not installed by default. RTools42 by default uses mingw32.static.posix for which we can not install mingw32-make.

The first line we need to add to make/local is to silence some warnings caused by TBB with g++ 11. Newer versions of TBB do not spit out this warning.

The second line to make/local is due to a bug in MinGW that incorrectly sets the version of MSVCRT which causes the compiler to think it does not have support for some functions, though it does have it - this mainly affects std::at_quick_exit and std::quick_exit. That causes errors like the one here. This had been fixed in MinGW as I can see here but seems to not make its way into Rtools42 I guess. We should report this to Rtools I think, though I am not sure where is the best place to do that.

However, since Torsten/cmdstan/make does not have a local file, I have copied the local file over from the vanilla cmdstan version and modified it accordingly. This is how the file looks like:

CXXFLAGS += -Wno-nonnull
TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00
CXXFLAGS += -Wno-deprecated-declarations

I am now able to compile the example pk2cpt.stan file and the output was similar to the one described in this blog post, so I assume it is correct. If my assessment is correct and mingw32-make is not part of the newer RTools versions, maybe a hint somewhere on the installation page would be helpful. Feel free to close this issue (unless there is something to add). Thanks!

from torsten.

yizhang-yiz avatar yizhang-yiz commented on May 12, 2024 1

Thanks a lot for investigating on this. I'll add instructions to the new release.

from torsten.

marianklose avatar marianklose commented on May 12, 2024

Maybe two additional comments:

I have a fresh installation of Rtools (rtools43) and apparently the distribution doesn't come with mingw32-make (see stan-dev/cmdstan#1064). I have followed 2 steps there to make mingw32-make available:

  • Add C:\rtools43\usr\bin and C:\rtools43\ucrt64\bin to the PATH
  • Run pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc in a freshly opened Powershell

Now I get

H:\>mingw32-make --version

GNU Make 4.4
Built for Windows32
Copyright (C) 1988-2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

But the issue is still persistent unfortunately. There was another advice to put two lines into make/local, but I was not sure where exactly I need to put them (make/local is not existent) so I skipped this for now.

Add the following two lines to the make/local:
CXXFLAGS += -Wno-nonnull
TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00

Furthermore, I have no problems running / compiling an example .stan model using the vanilla cmdstan version:

set_cmdstan_path("C:/.cmdstan/cmdstan-2.33.1")

CmdStan path set to: C:/.cmdstan/cmdstan-2.33.1

cmdstan_path()

[1] "C:/.cmdstan/cmdstan-2.33.1"

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

Model executable is up to date!

mod$print()

data {
int<lower=0> N;
array[N] int<lower=0,upper=1> y;
}
parameters {
real<lower=0,upper=1> theta;
}
model {
theta ~ beta(1,1); // uniform prior on interval 0,1
y ~ bernoulli(theta);
}

mod$exe_file()

[1] "C:/.cmdstan/cmdstan-2.33.1/examples/bernoulli/bernoulli.exe"

# names correspond to the data block in the Stan program
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))

fit <- mod$sample(
    data = data_list,
     seed = 123,
     chains = 4,
     parallel_chains = 4,
     refresh = 500 # print update every 500 iters
 )

Running MCMC with 4 parallel chains...

Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 1 Iteration: 500 / 2000 [ 25%] (Warmup)
Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
...

from torsten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.