pyhf.optimize not introspectable with inspect.getsource et al.
See original GitHub issueDescription
Trying to use inspect (from the stdlib) to inspect the source of pyhf.optimize raises an AttributeError.
Expected Behavior
The inspect functions should work and return the source code.
Steps to Reproduce
With pyhf 0.6.1 and python 3.7.6:
import pyhf
import inspect
# this works when you replace pyhf.optimize with sys.modules[type(pyhf.optimize).__module__]
for l in inspect.getsourcelines(pyhf.optimize)[0]: print(l)
Checklist
- Run
git fetchto get the most up to date version ofmaster - Searched through existing Issues to confirm this is not a duplicate issue
- Filled out the Description, Expected Behavior, Actual Behavior, and Steps to Reproduce sections above or have edited/removed them in a way that fully describes the issue
NB: I am not sure how this relates to #735 and #1402 . Would using def __getattr__(): <...> fix this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
iminuit v1.5.0 breaks optimization tests #1069 - scikit-hep/pyhf
The new version passes all the iminuit tests, including minimization tests on difficult functions, so I am not sure what is going on...
Read more >Source code for pyhf.optimize.opt_minuit - Scikit-HEP
Source code for pyhf.optimize.opt_minuit. """Minuit Optimizer Class.""" from pyhf import exceptions from pyhf.optimize.mixins import OptimizerMixin import ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@lhenkelm My apologies for the overly curt replies on Friday — that wasn’t helpful and definitely not encouraging behavior for you to have further interactions with the project or Scikit-HEP.
I also failed to say thanks for using
pyhfin the first place. 😃 We do appreciate people adopting it into their workflows and even more the people who care enough about it to open Issues and discuss with us.From the above replies, I think it is safe to say that in addition to checking the docs website that is generated from the codebase docstrings, we could probably do a better job in the public API of distinguishing between what is actually meant for the user. PR #1403 will help with this to some extent (as you already noted — thanks for also actually reading through Issues before opening this one 👍) and revisions related to Issue #735 will allow us to further clean up the public API as well so that things like trying to understand the between
optimizevs.optimizerhopefully won’t be something users have to think about at all.I’ll leave this closed for now, as it will be linked in the Issues we just mentioned and this is more related to the
_OptimizerRetrieverclass that users shouldn’t need to interact with, but if there are additional things worth discussing here please let us know and we’re more than happy to reopen.Hi @matthewfeickert, thanks for the heads up! This is a very nice improvement for interactive exploration of the API. In particular, I notice the REPL / notebook tab-completion will now suggest
pyhf.optimizerwhen prompted withpyhf.opt<+tab>(or similar), which as you & @lukasheinrich noted above, has a much more helpful documentation thanpyhf.optimize.One thing I am now wondering about: would it make sense to foolproof the interactive help even more by putting in a reference to the useful names to interrogate using help(…)? I.e. a line in the
_OptimizerRetrieverdocstring to the effect of “The currently used optimizer is documented at pyhf.optimizer. For optimization using the iminuit backend refer to pyhf.optimize.minuit_optimizer. (etc.)”.The same references could go in the module docstring too, but then the
_OptimizerRetrieverwould need to be replaced/extended to allow the module docstring to be found. That way I would get the same redirection when clicking through the online API docs (and the alternative optimizers would be listed by help automatically, so no need to keep track in a docstring). But I believe you had good reasons to use the retriever, so I don’t want to ignorantly suggest scrapping it without understanding its purpose.