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

calculate should suggest variables it is missing when it can't calculate a quantity #1

Open
mcgibbon opened this issue Nov 5, 2015 · 5 comments

Comments

@mcgibbon
Copy link
Contributor

mcgibbon commented Nov 5, 2015

Sometimes a user might forget that a certain quantity is needed to calculate the output they want. In these cases, an exception with the message "can't calculate quantity from inputs" is raised. It would be useful if this message indicated the smallest set of quantities that need to be additionally supplied in order to calculate the desired output quantity.

This enhancement involves tinkering with the fairly complicated equation system solver code, or making code that has some of its qualities, so if you're interested in taking this on please talk to me.

@sunt05
Copy link
Contributor

sunt05 commented May 16, 2020

First of all, this is indeed a great piece of code and I use it in my daily work for various conversions.

This feature would be a nice addition if could be implemented.

@mcgibbon
Copy link
Contributor Author

Thanks @sunt05 ! When I made it, the package never seemed to get much of a user base, so I eventually stopped working on it. I remember there was some kind of issue (maybe with setuptools?) causing CI to fail. That would need to be fixed also in order to test any changes. If you're interested in implementing this I'd be happy to give some pointers!

@sunt05
Copy link
Contributor

sunt05 commented May 18, 2020

That would be great if some hints are provided!
Cannot guarantee a timeframe for the implementation but I'd be very happy to contribute.

@mcgibbon
Copy link
Contributor Author

In terms of fixing the CI, I can't even remember what the issue was, but if you find out what that was feel free to ask me for help if you need it. My email right now is [email protected].

In terms of writing this feature, there are two useful existing functions/features:

  • the private method _get_methods on BaseSolver which gives you a dictionary of functions (not "methods", bad naming on my part) that can compute an output. The keys are the output variable.
  • the function get_calculatable_quantities will tell you all the things you can compute from what you have.

Basically, you could write a function (probably as a method on BaseSolver) which looks at the functions which can compute the output you want, and figures out which one has the fewest inputs you don't already have in the result from get_calculatable_quantities. Then it returns this minimal set of missing inputs. If there are multiple functions with the same number of missing inputs, you could choose one arbitrarily (the first one is fine).

The place where you will need to raise this exception is at line 543 of solve.py. I'd suggest adding something like ", could be calculated with e.g. in addition to inputs" to the error message.

@mcgibbon
Copy link
Contributor Author

mcgibbon commented May 18, 2020

Ah additionally, you can get the list of inputs to a function using args = tuple(getfullargspec(func).args). getfullargspec is imported from inspect at the top of solve.py.

@sunt05 sunt05 mentioned this issue May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants