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

Create a Model from a constant expression returns an error #355

Open
patquem opened this issue Oct 25, 2022 · 2 comments
Open

Create a Model from a constant expression returns an error #355

patquem opened this issue Oct 25, 2022 · 2 comments

Comments

@patquem
Copy link

patquem commented Oct 25, 2022

Hello,
doing Model({y: 0.}) or CallableModel({y: 0.}) (whatever the constant value in the expression) returns:
AttributeError: 'float' object has no attribute 'free_symbols'
That is a problem when, for instance, we want to create a model after n-derivations and variables are no longer present in the expression.
Could please fix that or tell me if a work around exists.
Thanks,
Patrick

@pckroon
Copy link
Collaborator

pckroon commented Oct 27, 2022

Interesting use-case! This is definitely something I'd like to fix, but I'm not sure on what kind of time-line. With a bit of luck I'll manage a PR within a week or so.
In the meantime you can try something along the following lines: Model({y: sympy.Expr(0)}). No idea if that works though.

@tBuLi
Copy link
Owner

tBuLi commented Nov 16, 2022

Yes that would work. The PR for this should be really simple actually, because sympy already has a method sympify that does exactly this. So we should first check if the value is an Expr, and if it isn't we call sympify on it. We can probably not call sympify on all our input without checking, because I'm not sure what that would do to e.g. Parameters.

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

3 participants