stan-dev / cmdstanpy

CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to compile a Stan program and fit the model to data using CmdStan.
BSD 3-Clause "New" or "Revised" License
149 stars 67 forks source link

undefined reference error after installing cmdstan with `install_cmdstan --compiler` on windows gh actions #722

Closed teddygroves closed 6 months ago

teddygroves commented 6 months ago

Summary:

I maintain a Python package that depends on cmdstan via cmdstanpy, and it hit this error when running a github action on windows.

Description:

The action that I made installs cmdstan on windows in a fresh environment with the command install cmdstan --compiler and runs a simple stan model.

I think this is the most important bit of the error message (line 800):

C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/cmdstan/main.o:main.cpp:(.text$_ZN4stan2io15stan_csv_reader12read_samplesERSiRN5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEERNS0_15stan_csv_timingEPSo[_ZN4stan2io15stan_csv_reader12read_samplesERSiRN5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEERNS0_15stan_csv_timingEPSo]+0x75d): undefined reference to `std::istream::seekg(std::fpos<int>)'

The same action went through fine on the ubuntu-latest platform, so I think the problem might have something to do with how cmdstanpy installs cmdstan on windows.

To check that the problem wasn't something to do with the rest of the package, I created a new repository specifically to test this bug. The new repo contains only a bernoulli stan program and json data input copied from cmdstanpy, a script script.py with this code:

import cmdstanpy

model = cmdstanpy.CmdStanModel(stan_file="bernoulli.stan")
mcmc = model.sample(data="bernoulli.data.json")

and finally a github action with these lines:

# This workflow tests bibat by using it to make a project, then running the new project's tests.

name: Install cmdstan on windows and run the bernoulli model

on: push

jobs:
  build:

    runs-on: ${{ matrix.os }}

    strategy:
        matrix:
            os: [windows-latest]
            python-version: ["3.10"]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install cmdstanpy
      run: pip install cmdstanpy
    - name: Install cmdstan
      run: install_cmdstan --compiler
    - name: Run script
      run: python script.py

Running this action led to a very similar error to the one I started with.

Additional Information:

Please let me know if you think this bug belongs more to cmdstan rather than cmdstanpy and I'll move it over!

Current Version:

cmdstan version: 2.33.1 cmdstanpy version: 1.2.0

WardBrian commented 6 months ago

I think this might be because of GitHub updating their windows runners to a newer MinGW a while back (when was the last time you successfully ran this action?)

If so, a fix is in the next version: https://github.com/stan-dev/math/pull/2948. For now in cmdstanpy we are manually setting some extra flags in our windows portion of the action, which you could try, or try “—version git:develop” in the install_cmdstan call

teddygroves commented 6 months ago

Thanks a lot! Just adding --version git:develop didn't work (see run here) but copying the TBB_CXXFLAGS = "-D_UCRT" lines from cmdstanpy's github actions as well did.

WardBrian commented 6 months ago

Adding git:develop worked when I forked your repo to try debugging: https://github.com/WardBrian/cmdstanpy-windows/actions/runs/7265449477/job/19795148846

Weird!

teddygroves commented 6 months ago

Yeah I don't understand why this action failed. Maybe something was cached since I was running very similar actions in quick succession?

Anyway I guess the main problem is solved!