8000 Error about invalid name when making an SUJohnson PDF? · Issue #611 · zfit/zfit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Error about invalid name when making an SUJohnson PDF? #611

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

Open
acampove opened this issue Feb 26, 2025 · 3 comments
Open

Error about invalid name when making an SUJohnson PDF? #611

acampove opened this issue Feb 26, 2025 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@acampove
Copy link

Bugs Please fill the below form if possible.

It seems that I cannot use names that start with _ when making JohnsonSU PDFs.

You should be able to reproduce the problem with:

import zfit

obs = zfit.Space('B_M', limits=(4500, 6000))
mu  = zfit.param.Parameter('mu_suj', 5300, 4000, 6000)
sg  = zfit.param.Parameter('sg_suj',   10,    2, 1000)
gm  = zfit.param.Parameter('gm_suj',    1,  0.1,   10)
dl  = zfit.param.Parameter('dl_suj',    1,  0.1,   10)

pdf = zfit.pdf.JohnsonSU(mu, sg, gm, dl, obs, name='_name')
dat = pdf.create_sampler(n=10_000)

nll          = zfit.loss.UnbinnedNLL(model=pdf, data=dat)
minimizer    = zfit.minimize.Minuit()
result       = minimizer.minimize(nll)

if you use name instead of _name, the error goes away.

Current Behaviour

I would expect to be able to use any name, as with the other PDFs.

2025-02-26 11:15:33.666113: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1740539733.677244  209190 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1740539733.680699  209190 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2025-02-26 11:15:35.804243: E external/local_xla/xla/stream_executor/cuda/cuda_driver.cc:152] failed call to cuInit: INTERNAL: CUDA error: Failed call to cuInit: UNKNOWN ERROR (303)
Traceback (most recent call last):
  File "/home/acampove/Tests/zfit/suj/test.py", line 10, in <module>
    dat = pdf.create_sampler(n=10_000)
  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py", line 588, in new_func
    return func(*args, **kwargs)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1127, in create_sampler
    return SamplerData.from_sampler(
  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py", line 588, in new_func
    return func(*args, **kwargs)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/data.py", line 1450, in from_sampler
    init_val, init_weights = sample_and_weights_func(n, params)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/data.py", line 1439, in sample_and_weights_func
    return sample_func(n, params), None
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1125, in sample_func
    return self.sample(n=n, limits=limits, params=params).value()
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1196, in sample
    tensor = run_tf(n=n, limits=limits, x=xclean)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1192, in run_tf
    return self._single_hook_sample(n=n, limits=limits, x=x)  # todo: make data a composite object
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/z/zextension.py", line 332, in concrete_func
    result = func_to_run(*args, **kwargs)
  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1202, in _single_hook_sample
    return self._hook_sample(n=n, limits=limits)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basepdf.py", line 787, in _hook_sample
    samples = super()._hook_sample(limits=limits, n=n)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1205, in _hook_sample
    return self._limits_sample(n=n, limits=limits)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1209, in _limits_sample
    return self._call_sample(n=n, limits=limits)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/core/basemodel.py", line 1237, in _call_sample
    return self._analytic_sample(n=n, limits=limits)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/models/dist_tfp.py", line 119, in _analytic_sample
    return tfd_analytic_sample(n=n, dist=self.distribution, limits=limits)
  File "/home/acampove/.local/lib/python3.9/site-packages/zfit/models/dist_tfp.py", line 102, in distribution
    return self._distribution(**params, **kwargs, name=self.name + "_tfp")
  File "/home/acampove/.local/lib/python3.9/site-packages/decorator.py", line 235, in fun
    return caller(func, *(extras + args), **kw)
  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow_probability/python/distributions/distribution.py", line 342, in wrapped_init
    default_init(self_, *args, **kwargs)
  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow_probability/python/distributions/johnson_su.py", line 169, in __init__
    with tf.name_scope(name or 'JohnsonSU') as name:
  File "/usr/lib64/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
ValueError: '_name_tfp' is not a valid root scope name. A root scope name has to match the following pattern: ^[A-Za-z0-9.][A-Za-z0-9_.\\/>-]*$

Expected Behaviour

Context (Environment)

  • zfit version: 0.24.3
  • Python version: 3.9.21
  • Are you using conda, pipenv, etc? : micromamba
  • Operating System: AlmaLinux 9
  • Tensorflow version: tensorflow-2.18.0-cp39-cp39

Possible Solution/Implementation

8000
@acampove acampove added the bug Something isn't working label Feb 26, 2025
@ikrommyd
Copy link
Contributor
ikrommyd commented Feb 26, 2025

That looks like intentional tensorflow design. The error is happening when a name scope is created here in tensorflow probability code

  File "/home/acampove/.local/lib/python3.9/site-packages/tensorflow_probability/python/distributions/johnson_su.py", line 169, in __init__
    with tf.name_scope(name or 'JohnsonSU') as name:

and is being raised directly from tensorflow:
https://github.com/tensorflow/tensorflow/blob/318211733753169cc75f1e07b46ae1dda03c53c7/tensorflow/python/framework/ops.py#L3398

Tensorflow wants to allow only root scope names with this pattern: ^[A-Za-z0-9.][A-Za-z0-9_.\\/>-]*$

acampove pushed a commit to acampove/dmu that referenced this issue Mar 1, 2025
@jonas-eschle
Copy link
Contributor

Hi @acampove thanks for spotting this! I think the naming was something that we never fully restricted, but the longer the more we should just do that. The name should be something identifiable, something that maybe can be restored, a token.
On the other hand, most zfit objects (PDFs, parameters, space,...) offer a label= which can be anything. The label is not meant to be used to ever retrieve a PDF but to display it (i.e. in plotting etc.)

@jonas-eschle
Copy link
Contributor
jonas-eschle commented Apr 10, 2025

Well, I would suggest to add something similar, ^[A-Za-z0-9.][A-Za-z0-9_.\\/>-]*$ is probably reasonable. This could be rather easy to do, actually

@jonas-eschle jonas-eschle added help wanted Extra attention is needed good first issue Good for newcomers labels Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants
0