Giter Club home page Giter Club logo

tf-pwa's Introduction

A Partial Wave Analysis program using Tensorflow

Documentation build status CI status Test coverage conda cloud pypi license
Binder pre-commit Prettier Code style: black Imports: isort

This is a package and application for partial wave analysis (PWA) using TensorFlow. By using simple configuration file (and some scripts), PWA can be done fast and automatically.

Install

You can go to http://tf-pwa.readthedocs.io/install for more informations. Get the packages using

git clone https://github.com/jiangyi15/tf-pwa.git

The dependencies can be installed by conda or pip.

conda (recommended)

When using conda, you don't need to install CUDA for TensorFlow specially.

  1. Get miniconda for python3 from miniconda3 and install it.

  2. Install requirements, we recommed Ampere card users to install with tensorflow_2_6_requirements.txt (see this technical FAQ).

You can install a tensorflow gpu version in anaconda as

conda install tensorflow[build="gpu*"]=2.8

and then install the rest dependences

conda install --file requirements-min.txt

Or

You can install a newer version in conda-forge as

conda install --file tensorflow_2_6_requirements.txt -c conda-forge
  1. The following command can be used to set environment variables of Python. (Use --no-deps to make sure that no PyPI package will be installed. Using -e, so it can be updated by git pull directly.)
python -m pip install -e . --no-deps
  1. (option) There are some option packages, such as uproot for reading root file. It can be installed as
conda install uproot -c conda-forge
### conda channel (experimental)

A pre-built conda package (Linux only) is also provided, just run following command to install it.

conda config --add channels jiangyi15
conda install tf-pwa

### pip

When using `pip`, you will need to install CUDA to use GPU. Just run the following command :

python3 -m pip install -e .

To contribute to the project, please also install additional developer tools with:

python3 -m pip install -e .[dev]

Scripts

fit.py

simple fit scripts, decay structure is described in config.yml, here [] means options.

python fit.py [--config config.yml]  [--init_params init_params.json]

fit parameters will save in final_params.json, figure can be found in figure/.

state_cache.sh

script for cache state, using the latest *_params.json file as parameters and cache newer files in path (the default is trash/).

./state_cache.sh [path]

Documents

See tf-pwa.rtfd.io for more information.

Autodoc using sphinx-doc, need sphinx-doc

python setup.py build_sphinx

Then, the documents can be found in build/sphinx/index.html.

Documents can also build with Makefile in docs as

cd docs && make html

Then, the documents can be found in docs/_build/html.

Other resources

面向 BESIII 用户的 TF-PWA 使用手册

HADRON 2023

PWA 12

Dependencies

tensorflow or tensorflow-gpu >= 2.0.0

cudatoolkit : CUDA library for GPU acceleration

sympy : symbolic expression

PyYAML : config.yml file

matplotlib : plot

scipy : fit

tf-pwa's People

Contributors

amishgog avatar jiangyi15 avatar redeboer avatar tdayu avatar wwdws1 avatar yinrui-liu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tf-pwa's Issues

Problem with TF-PWA install

Hello, Mr. Jiang. I am a first-year graduate student and I am learning the use of TFPWA recently. During this process, the following problems were discovered:
1.During the software installation process, I found that tensorflow-gpu=2.2 and tensorflow-gpu=2.4 could not be found in miniconda3.
2.I installed TensorFlow-gpu=2.6, but tensorflow_2_6_requirements was not available when I installed the dependency. I changed the content of tensorflow_2_6_requirements compared with the installed list, which is as follows(Other dependencies were installed when TensorFlow-gpu2.6 was installed):

matplotlib
pyyaml
setuptools_scm<7.0
sympy

Then, when I ran python gen_toy.py under the tutorials folder, an error occurred:

AttributeError: module 'numpy' has no attribute 'object'.
np.object was a deprecated alias for the builtin object. To avoid this error in existing code, use object by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

I think many of the versions I relied on during the installation of TFPWA were not compatible and may have caused these errors.
May I ask what I should do next

In addition, my graphics card version is NVIDIA GeForce GT 730, and I checked that the cuda version it can support is CUDA11.4

Problem when using save_root

I am trying to use save_root to create root file as: "config.plot_partial_wave(smooth=True,save_root=True)". However, I get the error that "AttributeError: module 'uproot' has no attribute 'newtree'". I have checked uproot has been installed successfully. The version of uproot is 4.2.2.

Do you have any idea about it?

Problem with the TF-PWA angulare distributions

I continued the comparison and started to look into the channel D1->K+K-K0 with an a1 in the intermediate state.

There we have the problem that the model of TF-PWA the angulares distributions are modeled flat.

D(1)(2420)0_R_K~0K+_cos(beta)
R_K0K+_K0_alpha
(Black is data from Tensorwaves and rad the model of TF-PWA)

In our opinion the distribution shouldn't be flat.
I used the following config file:
config.txt

I hope you have an idea what is going on.

Bug: Problem simulating/fitting with a parent particle with spin 0

I try to work on the suggestion of Wenbin and look into a decay only containing spin 0 particles (and compare the two tools).

I tried the decay chain D*(2300)0-> K+K- K0 with a(1450) and f(1370) as resonances.

Here is the config file I´m using: config.txt

While loading the config following shows up:

integer division or modulo by zero D(0)*(2300)0->a(0)(1450)0+K~0 ()
integer division or modulo by zero D(0)*(2300)0->f(0)(1370)+K~0 ()
integer division or modulo by zero D(0)*(2300)0->a(0)(1450)++K- ()
integer division or modulo by zero D(0)*(2300)0->a(0)(1450)-+K+ ()

and while simularing following error occurs (using the tutorial file for this) :

Traceback (most recent call last):
  File "gen_toy.py", line 62, in <module>
    main()
  File "gen_toy.py", line 25, in main
    generate_toy_from_phspMC(
  File "gen_toy.py", line 50, in generate_toy_from_phspMC
    data = gen_data(
  File "/home/leonard/work/src/tf-pwa/tf_pwa/applications.py", line 255, in gen_data
    ampsq = amp(phsp)
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 1704, in __call__
    ret = self.decay_group.sum_amp(data)
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 1478, in sum_amp
    amp = self.get_amp(data)
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 1410, in get_amp
    amp = decay_chain.get_amp(
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 1195, in get_amp
    amp_d.append(i.get_amp(data_c[i], data_p, all_data=all_data))
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 951, in get_amp
    H = self.get_helicity_amp(data, data_p, **kwargs)
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 811, in get_helicity_amp
    m_dep = self.get_ls_amp(data, data_p, **kwargs)
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 890, in get_ls_amp
    bf = self.get_barrier_factor2(
  File "/home/leonard/work/src/tf-pwa/tf_pwa/amp/__init__.py", line 934, in get_barrier_factor2
    ret = tf.concat(ret, axis=-1)
  File "/home/leonard/anaconda3/envs/tw/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "/home/leonard/anaconda3/envs/tw/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 1654, in concat
    return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
  File "/home/leonard/anaconda3/envs/tw/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1207, in concat_v2
    _ops.raise_from_not_ok_status(e, name)
  File "/home/leonard/anaconda3/envs/tw/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 6843, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: OpKernel 'ConcatV2' has constraint on attr 'T' not in NodeDef '[N=0, Tidx=DT_INT32]', KernelDef: 'op: "ConcatV2" device_type: "CPU" constraint { name: "T" allowed_values { list { type: DT_UINT64 } } } host_memory_arg: "axis"' [Op:ConcatV2] name: concat

I hope you can help me and find the bug.
The only thing I noticed is that this does not happen when I change the spin of the D(2300) to 1.

Thanks in advanced.

Improve developer environment

This issue serves more as an epic to outline what changes I have in mind, so that the purpose of the (upcoming) PRs is clearer.

  • Formatting
    Additional formatters can easily be implemented through pre-commit (since #2). It's easy to add some configurations, but, as with #2, it is best if @jiangyi15 does the actual formatting (to keep the commits attributed to him as the original developer).
    For the ComPWA repositories, we have good experience with:
  • Documentation (Read the Docs)
    • Automatically generate the API with sphinx-apidoc --> #7
    • Make more heavy use of intersphinx. This is both to help the reader when navigating through the site, as well as to inform us when documentation becomes outdated (see linkcheck).--> #7
    • Run the linkcheck builder in the CI. This forces us to keep the documentation up to date --> #7
    • Implement rstcheck and doc8 through pre-commit. These are linters for reStructuredText. --> #7
    • Activate the nitpicky option and fix linking errors in the documentation.
    • Put installation and contribute instructions on the RTD pages as well.
    • Write usage instructions in terms of Jupyter notebooks and run them in the CI and on RTD (nbsphinx). This way, you (1) make sure that the instructions remain up-to-date and (2) cell output is nicely rendered on the web pages.
  • Linters
    These are the most complicated ones, as they often require some refactoring of the code. I therefore don't intend on implementing them any time soon.
    • Enforce pylint through pre-commit. Currently pylint is only run in the CI and only generates warnings. --> #8
    • flake8 as well as several additional extensions
    • pydocstyle: my experience is that it is more configurable than other linters that check docstrings.
    • mypy: would be a bigger decision actually, because this would mean supplying type hints everywhere
  • Automate: allow the developer to run all CI checks locally as well through tox

I also have some ideas for GitHub (release drafter etc), but that can be done another time.

Plans for better description of decays

There are many ways can be implemeted to simplify the current description of decays.

  • Replace rules : support replace decay node with particles name when it is list.
    use
decay:
    A: 
    - [ R, B]
    R: [ C, D]
particle:
     R: [R1, R2]

to produce

decay:
    A: 
    - [ R1, B ]
    - [ R2, B ]
    R1: [ C, D ]
    R2: [ C, D ]
  • Properities from Resonaces.yml and override in config.yml.
    use
# in Resonances.yml
R1:
    J: 1
    P: +1
    mass: 1.0
    width: 0.05
# in config.yml
particle:
   R1:  
      mass:  1.1

to produce

# in config.yml
particle:
  R1:
      J: 1
      P: +1
      mass: 1.1
      width: 0.05
  • Support multiply particles of top nodes. (A -> B C D, B -> E F G)
    • aligned in each parts to avoid much combination.
    • combine the amplitude of them like a decay chain.
  • Better way to deal with identical particles.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.