Coder Social home page Coder Social logo

Comments (6)

WardBrian avatar WardBrian commented on May 28, 2024

This error sounds like Python is preferring to load the folder called bridgestan over the Python module. The easiest thing to do is probably to re-name the downloaded bridgestan to something like bridgestan_repo and then pip install bridgestan_repo/python

from bridgestan.

fredhu0514 avatar fredhu0514 commented on May 28, 2024

Hi, I updated the module import, but it shows a new error.

import bridgestan.python.bridgestan as bs
import numpy as np

stan = "../test_models/bernoulli/bernoulli.stan"
data = "../test_models/bernoulli/bernoulli.data.json"
model = bs.StanModel.from_stan_file(stan, data)

print(f"This model's name is {model.name()}.")
print(f"It has {model.param_num()} parameters.")

x = np.random.random(model.param_unc_num())
q = np.log(x / (1 - x))  # unconstrained scale
lp, grad = model.log_density_gradient(q, jacobian=False)
print(f"log_density and gradient of Bernoulli model: {(lp, grad)}")

Error msg:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-22-fb3d9974c29f>](https://localhost:8080/#) in <module>
      4 stan = "../test_models/bernoulli/bernoulli.stan"
      5 data = "../test_models/bernoulli/bernoulli.data.json"
----> 6 model = bs.StanModel.from_stan_file(stan, data)
      7 
      8 print(f"This model's name is {model.name()}.")

[/content/bridgestan/python/bridgestan/model.py](https://localhost:8080/#) in from_stan_file(cls, stan_file, model_data, stanc_args, make_args, seed, chain_id)
    196         :raises RuntimeError: If compilation fails.
    197         """
--> 198         result = compile_model(stan_file, stanc_args=stanc_args, make_args=make_args)
    199         return cls(str(result), model_data, seed=seed, chain_id=chain_id)
    200 

[/content/bridgestan/python/bridgestan/compile.py](https://localhost:8080/#) in compile_model(stan_file, stanc_args, make_args)
     84 
     85     stanc_args
---> 86     output = generate_so_name(file_path)
     87     cmd = (
     88         [MAKE]

[/content/bridgestan/python/bridgestan/compile.py](https://localhost:8080/#) in generate_so_name(model)
     51 def generate_so_name(model: Path):
     52     name = model.stem
---> 53     return model.with_stem(f"{name}_model").with_suffix(".so")
     54 
     55 

AttributeError: 'PosixPath' object has no attribute 'with_stem'

from bridgestan.

WardBrian avatar WardBrian commented on May 28, 2024

That seems like you’re using a version of python earlier than 3.9, which is the minimum version we support. It’s possible changing that one thing is all you’d need to use an older version, but there could be more places we use 3.9 specific code

from bridgestan.

fredhu0514 avatar fredhu0514 commented on May 28, 2024

The error actually happened in Python 3.9.16. Here is the google colab file I'm running. Even in Python 3.9.16, the posix error keeps showing.

from bridgestan.

WardBrian avatar WardBrian commented on May 28, 2024

I ran your file and confirmed the output. But, I then added this cell:

import sys
sys.version

3.8.10 (default, Nov 14 2022, 12:59:47) \n[GCC 9.4.0]

The google collab kernel you are using seems to be detached from the python command in the collab workspace.

from bridgestan.

fredhu0514 avatar fredhu0514 commented on May 28, 2024

Interesting, thx!

from bridgestan.

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.