diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8e9f92f..97b122d 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -7,7 +7,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: "3.9" + python: "mambaforge-22.9" @@ -15,12 +15,7 @@ build: sphinx: configuration: docs/conf.py -formats: [ ] +conda: + environment: docs/environment.yml -python: - install: - - requirements: docs/additional_requirements.txt - - method: pip - path: . - extra_requirements: - - dev +formats: [ ] diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100755 index 0000000..3e7e2c9 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +/_build/ +/api/*.rst diff --git a/docs/api/static/zfit_physics.compwa.rst b/docs/api/static/zfit_physics.compwa.rst index 78dba30..15c7a4e 100644 --- a/docs/api/static/zfit_physics.compwa.rst +++ b/docs/api/static/zfit_physics.compwa.rst @@ -9,7 +9,7 @@ Import the module with: import zfit_physics.compwa as zcompwa -This will enable that :py:function:`~ tensorwaves.estimator.Estimator`, can be used as a loss function in zfit minimizers as +This will enable that a :py:class:`~ tensorwaves.estimator.Estimator`, for example ``estimator`` in the following, can be used as a loss function in zfit minimizers as .. code-block:: python diff --git a/docs/api/static/zfit_physics.roofit.rst b/docs/api/static/zfit_physics.roofit.rst index e6a0a77..2ae151c 100644 --- a/docs/api/static/zfit_physics.roofit.rst +++ b/docs/api/static/zfit_physics.roofit.rst @@ -11,26 +11,53 @@ For example via conda: $ mamba install -c conda-forge root +.. jupyter-execute:: + :hide-code: + :hide-output: + + import numpy as np + import zfit + from ROOT import RooArgSet, RooDataSet, RooGaussian, RooRealVar + + data = np.random.normal(loc=2.0, scale=3.0, size=1000) + + mur = RooRealVar("mu", "mu", 1.2, -4, 6) + sigmar = RooRealVar("sigma", "sigma", 1.3, 0.5, 10) + obsr = RooRealVar("x", "x", -2, 3) + RooFit_gauss = RooGaussian("gauss", "gauss", obsr, mur, sigmar) + + RooFit_data = RooDataSet("data", "data", {obsr}) + for d in data: + obsr.setVal(d) + RooFit_data.add(RooArgSet(obsr)) + + minimizer = zfit.minimize.Minuit() + Import the module with: -.. code-block:: python - import zfit_physics.roofit as ztfroofit -this will enable the RooFit functionality in zfit. +.. jupyter-execute:: -We can create a RooFit NLL as ``RooFit_nll`` and use it as a loss function in zfit. For example, with a Gaussian model ``RooFit_gauss`` and a dataset ``RooFit_data``, both created with RooFit: + import zfit_physics.roofit as zroofit + +this will enable the RooFit functionality in zfit and allow to automatically minimize the function using a zfit minimimzer as -.. code-block:: python +.. jupyter-execute:: RooFit_nll = RooFit_gauss.createNLL(RooFit_data) - minimizer.minimize(loss=RooFit_nll) + +We can create a RooFit NLL as ``RooFit_nll`` and use it as a loss function in zfit. For example, with a Gaussian model ``RooFit_gauss`` and a dataset ``RooFit_data``, both created with RooFit: + +.. jupyter-execute:: + + result = minimizer.minimize(loss=RooFit_nll) More explicitly, the loss function can be created with -.. code-block:: python +.. jupyter-execute:: - nll = zroofit.loss.nll_from_roofit(fcn) + nll = zroofit.loss.nll_from_roofit(RooFit_nll) Variables diff --git a/docs/api/static/zfit_physics.tfpwa.rst b/docs/api/static/zfit_physics.tfpwa.rst index 3c50bfb..a23d470 100644 --- a/docs/api/static/zfit_physics.tfpwa.rst +++ b/docs/api/static/zfit_physics.tfpwa.rst @@ -1,7 +1,7 @@ TF-PWA ======================= -TFPWA is a generic software package intended for Partial Wave Analysis (PWA). It can be connected with zfit, +TF-PWA is a generic software package intended for Partial Wave Analysis (PWA). It can be connected with zfit, currently by providing a loss function that can be minimized by a zfit minimizer. Import the module with: @@ -10,7 +10,7 @@ Import the module with: import zfit_physics.tfpwa as ztfpwa -This will enable that :py:function:`~tfpwa.model.FCN` can be used as a loss function in zfit minimizers as +This will enable that :py:class:`~tf_pwa.model.FCN` can be used as a loss function in zfit minimizers as .. code-block:: python diff --git a/docs/api/zfit_physics.models.pdf_argus.rst b/docs/api/zfit_physics.models.pdf_argus.rst deleted file mode 100644 index c9523dc..0000000 --- a/docs/api/zfit_physics.models.pdf_argus.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_argus -========== - -.. automodule:: zfit_physics.models.pdf_argus - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_cmsshape.rst b/docs/api/zfit_physics.models.pdf_cmsshape.rst deleted file mode 100644 index 7aeb83d..0000000 --- a/docs/api/zfit_physics.models.pdf_cmsshape.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_cmsshape -============= - -.. automodule:: zfit_physics.models.pdf_cmsshape - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_conv.rst b/docs/api/zfit_physics.models.pdf_conv.rst deleted file mode 100644 index be55ef7..0000000 --- a/docs/api/zfit_physics.models.pdf_conv.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_conv -========= - -.. automodule:: zfit_physics.models.pdf_conv - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_cruijff.rst b/docs/api/zfit_physics.models.pdf_cruijff.rst deleted file mode 100644 index 713107e..0000000 --- a/docs/api/zfit_physics.models.pdf_cruijff.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_cruijff -============ - -.. automodule:: zfit_physics.models.pdf_cruijff - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_erfexp.rst b/docs/api/zfit_physics.models.pdf_erfexp.rst deleted file mode 100644 index 7d1ed78..0000000 --- a/docs/api/zfit_physics.models.pdf_erfexp.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_erfexp -=========== - -.. automodule:: zfit_physics.models.pdf_erfexp - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_example.rst b/docs/api/zfit_physics.models.pdf_example.rst deleted file mode 100644 index bd90dbd..0000000 --- a/docs/api/zfit_physics.models.pdf_example.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_example -============ - -.. automodule:: zfit_physics.models.pdf_example - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_kde.rst b/docs/api/zfit_physics.models.pdf_kde.rst deleted file mode 100644 index a64f8e1..0000000 --- a/docs/api/zfit_physics.models.pdf_kde.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_kde -======== - -.. automodule:: zfit_physics.models.pdf_kde - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_novosibirsk.rst b/docs/api/zfit_physics.models.pdf_novosibirsk.rst deleted file mode 100644 index d4ef65e..0000000 --- a/docs/api/zfit_physics.models.pdf_novosibirsk.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_novosibirsk -================ - -.. automodule:: zfit_physics.models.pdf_novosibirsk - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_relbw.rst b/docs/api/zfit_physics.models.pdf_relbw.rst deleted file mode 100644 index bd768c9..0000000 --- a/docs/api/zfit_physics.models.pdf_relbw.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_relbw -========== - -.. automodule:: zfit_physics.models.pdf_relbw - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_tsallis.rst b/docs/api/zfit_physics.models.pdf_tsallis.rst deleted file mode 100644 index 97e4fd4..0000000 --- a/docs/api/zfit_physics.models.pdf_tsallis.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_tsallis -============ - -.. automodule:: zfit_physics.models.pdf_tsallis - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.rst b/docs/api/zfit_physics.models.rst deleted file mode 100644 index 61c19a7..0000000 --- a/docs/api/zfit_physics.models.rst +++ /dev/null @@ -1,24 +0,0 @@ -models -====== - -.. automodule:: zfit_physics.models - :members: - :undoc-members: - :show-inheritance: - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.models.pdf_argus - zfit_physics.models.pdf_cmsshape - zfit_physics.models.pdf_conv - zfit_physics.models.pdf_cruijff - zfit_physics.models.pdf_erfexp - zfit_physics.models.pdf_example - zfit_physics.models.pdf_kde - zfit_physics.models.pdf_novosibirsk - zfit_physics.models.pdf_relbw - zfit_physics.models.pdf_tsallis diff --git a/docs/api/zfit_physics.pdf.rst b/docs/api/zfit_physics.pdf.rst deleted file mode 100644 index 13c0245..0000000 --- a/docs/api/zfit_physics.pdf.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf -=== - -.. automodule:: zfit_physics.pdf - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.rst b/docs/api/zfit_physics.rst deleted file mode 100644 index 51e5dc0..0000000 --- a/docs/api/zfit_physics.rst +++ /dev/null @@ -1,24 +0,0 @@ -zfit\_physics package -===================== - -.. automodule:: zfit_physics - :members: - :undoc-members: - :show-inheritance: - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - zfit_physics.models - zfit_physics.unstable - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.pdf diff --git a/docs/api/zfit_physics.unstable.pdf.rst b/docs/api/zfit_physics.unstable.pdf.rst deleted file mode 100644 index 79e75f0..0000000 --- a/docs/api/zfit_physics.unstable.pdf.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf -=== - -.. automodule:: zfit_physics.unstable.pdf - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.unstable.rst b/docs/api/zfit_physics.unstable.rst deleted file mode 100644 index 9f02a0d..0000000 --- a/docs/api/zfit_physics.unstable.rst +++ /dev/null @@ -1,15 +0,0 @@ -unstable -======== - -.. automodule:: zfit_physics.unstable - :members: - :undoc-members: - :show-inheritance: - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.unstable.pdf diff --git a/docs/conf.py b/docs/conf.py index 96397b2..4375033 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -335,6 +335,11 @@ "matplotlib": ("https://matplotlib.org/stable/", None), "pandas": ("https://pandas.pydata.org/docs/", None), "numpy": ("https://numpy.org/doc/stable/", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference/", None), + "tensorwaves": ("https://tensorwaves.readthedocs.io/latest/", None), + "zfit": ("https://zfit.readthedocs.io/en/latest/", None), + "tf_pwa": ("https://tf-pwa.readthedocs.io/en/latest/", None), + "pyhf": ("https://pyhf.readthedocs.io/en/latest/", None), } # -- Options for todo extension ---------------------------------------------- diff --git a/docs/environment.yml b/docs/environment.yml new file mode 100644 index 0000000..8546f08 --- /dev/null +++ b/docs/environment.yml @@ -0,0 +1,10 @@ +name: rtd38 +channels: + - conda-forge + - defaults +dependencies: + - python=3.9 + - root<=6.30 + - uv + - pip: + - ../[dev] diff --git a/docs/make_docs.sh b/docs/make_docs.sh index c3399bc..f9f914c 100755 --- a/docs/make_docs.sh +++ b/docs/make_docs.sh @@ -6,11 +6,10 @@ MAKE_DOCS_PATH="$( cd "$(dirname "$0")" ; pwd -P )" popd > /dev/null # generate the ReST files -echo "debug" -echo ${MAKE_DOCS_PATH}/../zfit_physics +#echo ${MAKE_DOCS_PATH}/../zfit_physics ls ${MAKE_DOCS_PATH} ls . -sphinx-apidoc -o ${MAKE_DOCS_PATH}/api ${MAKE_DOCS_PATH}/../zfit_physics -fMeT && \ +sphinx-apidoc -o ${MAKE_DOCS_PATH}/api ${MAKE_DOCS_PATH}/../src/zfit_physics -fMeT && \ python3 ${MAKE_DOCS_PATH}/api/tools/change_headline.py ${MAKE_DOCS_PATH}/api/zfit_physics.* && \ make -C ${MAKE_DOCS_PATH} clean && make -C ${MAKE_DOCS_PATH} html -j8 && \ echo "Documentation successfully built!" || echo "FAILED to build Documentation" diff --git a/tests/roofit/test_loss_compat.py b/tests/roofit/test_loss_compat.py deleted file mode 100644 index 8b9db51..0000000 --- a/tests/roofit/test_loss_compat.py +++ /dev/null @@ -1,67 +0,0 @@ -import numpy as np -import pytest - - -def test_loss_registry(): - _ = pytest.importorskip("ROOT") - # Copyright (c) 2024 zfit - - import zfit - - import zfit_physics.roofit as zroofit - - # create space - obs = zfit.Space("x", -2, 3) - - # parameters - mu = zfit.Parameter("mu", 1.2, -4, 6) - sigma = zfit.Parameter("sigma", 1.3, 0.5, 10) - - # model building, pdf creation - gauss = zfit.pdf.Gauss(mu=mu, sigma=sigma, obs=obs) - - # data - ndraw = 10_000 - data = np.random.normal(loc=2.0, scale=3.0, size=ndraw) - data = obs.filter(data) # works also for pandas DataFrame - - from ROOT import RooArgSet, RooDataSet, RooFit, RooGaussian, RooRealVar - - mur = RooRealVar("mu", "mu", 1.2, -4, 6) - sigmar = RooRealVar("sigma", "sigma", 1.3, 0.5, 10) - obsr = RooRealVar("x", "x", -2, 3) - gaussr = RooGaussian("gauss", "gauss", obsr, mur, sigmar) - - datar = RooDataSet("data", "data", {obsr}) - for d in data: - obsr.setVal(d) - datar.add(RooArgSet(obsr)) - - # create a loss function - nll = gaussr.createNLL(datar) - - nllz = zfit.loss.UnbinnedNLL(model=gauss, data=data) - - # create a minimizer - tol = 1e-3 - verbosity = 0 - minimizer = zfit.minimize.Minuit(gradient=True, verbosity=verbosity, tol=tol, mode=1) - minimizerzgrad = zfit.minimize.Minuit(gradient=False, verbosity=verbosity, tol=tol, mode=1) - - params = nllz.get_params() - initvals = np.array(params) - - with zfit.param.set_values(params, initvals): - result = minimizer.minimize(nllz) - - with zfit.param.set_values(params, initvals): - result2 = minimizer.minimize(nll) - - assert result.params['mu']['value'] == pytest.approx(result2.params['mu']['value'], rel=1e-3) - assert result.params['sigma']['value'] == pytest.approx(result2.params['sigma']['value'], rel=1e-3) - - with zfit.param.set_values(params, params): - result4 = minimizerzgrad.minimize(nll) - - assert result.params['mu']['value'] == pytest.approx(result4.params['mu']['value'], rel=1e-3) - assert result.params['sigma']['value'] == pytest.approx(result4.params['sigma']['value'], rel=1e-3)