Skip to content

Forward vs. back slashes killing path assertions during $sample calls when using WSL w/ Ubuntu #1113

@jr-free

Description

@jr-free

Describe the bug

When attempting to sample from the bernoulli example model with cmdstan installed via WSL (and importantly, running R from Windows), the $sample call fails with an assertion from validate_cmdstan_args(self). The complete format of the error message is below:

Error in validate_cmdstan_args(self) : 
  Assertion on 'self$data_file' failed: File does not exist: 'wsl$/Ubuntu/home/<username>/stan_models\RtmpAnJeRs\standata-81c673e5579.json'.

To Reproduce
See the steps below as well as the attached image in the additional context section.

  1. Set your TMP, TEMP, and TMPDIR environment variables in your .Renviron file to point to a location in the WSL filesystem.
TEMP=//wsl$/Ubuntu/<your-folder-here>
TMP=//wsl$/Ubuntu/<your-folder-here>
TMPDIR=//wsl$/Ubuntu/<your-folder-here>
  1. Start with R 4.5 inside the vanilla RGui.
  2. Clear the workspace for a clean-slate.
  3. Install cmdstanr using
install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))
  1. install_cmdstan(cores=2, wsl=T)
  2. Follow the these steps from the vignette to sample from the model.
  3. Witness error occur.

Expected behavior
Model should successfully sample and display warm-up and sampling output.

Operating system

Windows
Windows 10 Enterprise
Build 19045

WSL
WSL version: 2.6.1.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.66
MSRDC version: 1.2.6353
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.19045.6332

Ubuntu on WSL
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble

CmdStanR version number
0.9.0

Additional context

The error appears to be related to how R is interfacing with WSL and handling (or not) forward vs. back-slashes. But there could be something else going on here. Compilation works a-okay. After the call to the sampler some intermediate temporary files with garbage names are created and deleted. The exception is only thrown for standata-*.json files (setting the output_basename parameter didn't change anything).

I did some digging into the exception and traced back (very manually, could be incorrect) the root issue to the .wsl_check_exists function. See the attached image below.

cmdstanr:::validate_cmdstan_args -- calls --> cmdstanr:::assert_file_exists 
cmdstanr:::assert_file_exists -- calls --> cmdstanr:::check_file_exists
cmdstanr:::check_file_exists -- calls --> cmdstanr:::.wsl_check_exists

When supplying a path with mixtures of forward, backward, escaped-backward slashes, etc., various errors are thrown. However, when I correctly specify the path I see the function evaluate to TRUE.

Some observations: in the assertion, the leading // in the WSL path is chopped (path <- gsub("^./", "", path). This appears to influence the output of the .wsl_check_exists function. Similarly when R creates the temporary directory in the TMPDIR, it appends it using escaped back-slashes (because Windows 😑). Likewise, somewhere along the way the standata-*.json file is appended to it's parent using backslashes at some point. I'm sure this is another potential failure mode.

For some additional background on my motivations: I'm attempting to set up STAN on my work laptop to perform some sensitivity analyses. Like other folks have noted in the past, STAN compilation and sampling is GOD AWFUL thanks to Windows + enterprise security. Compilation through WSL drastically improved compile times, but when writing back to Windows, sampling time tanked (worse than just doing everything in Windows). So I am experimenting with having STAN live in the WSL world so I can have my cake and eat it too. Along the way I ran face first into this issue, and here we are.

To be transparent, it is very possible that I'm an idiot and completely missed something obvious. If that's the case, apologies for wasting everyone's time in advance 😓

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwindows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions