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
WIP: upd Monte-Carlo integration (vegasflow package) #407
base: develop
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…o mc_vegasflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, that looks quite nice so far!
zfit/core/integration.py
Outdated
events_limit = vf_options.get("events_limit", int(1e6)) | ||
list_devices = vf_options.get("list_devices") | ||
compilable = vf_options.get("compilable", True) | ||
verbose = vf_options.get("verbose", False) # get_verbosity() >= 0 (?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we can use the global zfit settings. What are the different verbosity levels in vegasflow? zfit goes from 0 to 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it's better to use vf's verbosity levels for convenience (4 levels) – added to docstring. However, it can be sync with zfit's levels in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's an additional effort to get this right. But it can also be called from outside, yeah
@@ -280,6 +312,60 @@ def test_mc_integration(chunksize, limits): | |||
).numpy() == pytest.approx(integral3, rel=0.03) | |||
|
|||
|
|||
def test_mc_vf_integration(): | |||
# simple examples | |||
num_integral = zintegrate.mc_vf_integrate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There comes a crucial thing: can this run with a z.function
wrapped? Because in the PDF, it usually will be.
You can also swap the default integration methods for PDFs and check if the tests still run, do they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried wrapped version and faced some issues. The thing is, vf's run_integration
is not intended to run under tf.function – there are some python control flow instructions (like "if" in print_iteration
and numpy math ops when computing results from iterations) and tf.Variable creation (which causes "ValueError: tf.function-decorated function tried to create variables on non-first call"). I tried to use tf.py_function, but it did not help (anyway, i think it's not a relevant option in case of graph-like z.function application). I keep on thinking how to handle this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, yep. that's a bit of a problem. One thing you can try is to run it in a tf.init_scope
or just make an issue with VF/ask them. That would be good to be solved somehow
func5_sigma_i = zfit.Parameter(f"sigma_{i}", func5_sigma) | ||
func5_gauss_i = zfit.pdf.Gauss(obs=func5_obs_i, mu=func5_mu_i, sigma=func5_sigma_i) | ||
func5_prod_gauss_lst.append(func5_gauss_i) | ||
func5_prod_gauss = zfit.pdf.ProductPDF(pdfs=func5_prod_gauss_lst[::-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move all of this inside a function
compilable: bool = True, | ||
verbose: bool = False, | ||
compilable: bool = False, | ||
verbose: int | str = 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verbose: int | str = 3, | |
verbose: int | str = 0, |
Let the default be quiet
Fixes #
Proposed Changes
Tests added
Checklist