Tensorwaves

Latest version: v0.4.12

Safety actively analyzes 682457 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 7

0.4.5

_See all documentation for this version [here](//tensorwaves.rtfd.io/en/0.4.5)._

πŸ› Bug fixes

- Expressions that contain [`sympy.Indexed`](https://docs.sympy.org/latest/modules/tensor/indexed.html#sympy.tensor.indexed.Indexed) can now be lambdified (427)

πŸ”¨ Internal maintenance

- TensorWaves can now be installed with any version of AmpForm above [v0.13.0](https://github.com/ComPWA/ampform/releases/tag/0.13.0) (#426)

πŸ“ Documentation

- Extended API docstrings in the `function` module (428)

πŸ–±οΈ Developer Experience

- All dependencies are now also [pinned](https://compwa-org.readthedocs.io/develop.html#pinning-dependency-versions) on Read the Docs (429)

0.4.4

_See all documentation for this version [here](https://tensorwaves.rtfd.io/en/0.4.4)._

πŸ› Bug fixes

- Default weights in [`ChiSquared`](https://tensorwaves.readthedocs.io/en/0.4.4/api/tensorwaves.estimator.html#tensorwaves.estimator.ChiSquared) are now computed from `observed_values` (421)</summary>

πŸ”¨ Internal maintenance

- TensorWaves can now be installed with [AmpForm v0.14.x](https://github.com/ComPWA/ampform/releases/tag/0.14.0) (#424)

πŸ“ Documentation

- Switched to [Chew-Mandelstam _S_-wave phase space factor](https://ampform.readthedocs.io/en/0.14.0/api/ampform.dynamics.phasespace.html#ampform.dynamics.phasespace.PhaseSpaceFactorSWave) in the [analytic continuation notebook](https://tensorwaves.readthedocs.io/en/0.4.4/amplitude-analysis/analytic-continuation.html) (#425)

0.4.3

_See all documentation for this version [here](https://tensorwaves.rtfd.io/en/0.4.3)._

πŸ”¨ Internal maintenance

* TensorWaves can now be installed with AmpForm v0.13.x (419)

0.4.2

_See all documentation for this version [here](https://tensorwaves.rtfd.io/en/0.4.2)._

πŸ’‘ New features

* Added minuit_modifier constructor argument (399)

πŸ› Bug fixes

* Speed-up prepare_caching() with sympy.Basic.xreplace (403)

πŸ”¨ Internal maintenance

<details>
<summary>Added support for AmpForm v0.12.3 (406)</summary>

AmpForm [v0.12.3](https://github.com/ComPWA/ampform/releases/tag/0.12.3) introduces a small change through https://github.com/ComPWA/ampform/pull/211: `BoostZ` etc becomes `BoostZMatrix`. This needs to be fixed in the TensorFlow printer.

</details>

<details>
<summary>Added support for AmpForm v0.12.4 (417)</summary>

Added TensorFlow printer instructions for `_BoostZMatrixImplementation` etc. See release notes [AmpForm v0.12.4](https://github.com/ComPWA/ampform/releases/tag/0.12.4).

</details>

<details>
<summary>Switched to new import attrs API (414)</summary>

See [`import attrs`](https://hynek.me/articles/import-attrs/#the-last-step-import-attrs) and [`attrs` TNG](https://www.attrs.org/en/21.4.0/names.html#attrs-tng).

</details>

πŸ“ Documentation

<details>
<summary>Added notebook button for Deepnote (400)</summary>

Closes https://github.com/ComPWA/repo-maintenance/issues/43

[![image](https://user-images.githubusercontent.com/29308176/149676020-8281cbb4-8cae-4e1a-a171-b451809ea993.png)](https://tensorwaves--400.org.readthedocs.build/en/400/usage.html)

</details>

<details>
<summary>Usage notebooks now show how to get a Hesse from FitResult.specifics (401)</summary>

Also fixes a small bug: callbacks that write to disk skip writing when computing the Hesse.

Preview [here](https://tensorwaves--401.org.readthedocs.build/en/401/usage/basics.html#minuit2).

</details>

<details>
<summary>Improved docstrings of prepare_caching() and create_cached_function() (403)</summary>

Improved the docstrings of both functions, preview [here](https://tensorwaves--403.org.readthedocs.build/en/403/api/tensorwaves.estimator.html#tensorwaves.estimator.create_cached_function).

</details>

<details>
<summary>Code examples now automatically to APIs as if it's an IDE (405)</summary>

- All code examples are now clickable with links to corresponding reference documentation (also external links APIs) with [`sphinx-codeautolink`](https://sphinx-codeautolink.readthedocs.io). Closes https://github.com/ComPWA/compwa-org/issues/106 [![image](https://user-images.githubusercontent.com/29308176/151720171-5627f6dc-fef7-4471-88c8-366e61680988.png)](https://tensorwaves--405.org.readthedocs.build/en/405/usage.html#generate-and-transform-data)
- Installed [`jupyterlab-myst`](https://github.com/executablebooks/jupyterlab-myst)
- Updated to the first non-beta black release [22.1.0](https://github.com/psf/black/releases/tag/22.1.0). Most important style effect: [no space around power operator `**`](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-breaks-binary-operators).

</details>

<details>
<summary>Second level in left sidebar is unfolded by default (407)</summary>

Links to `graphviz`'s API are now also embedded correctly. Follow-up to 405.

</details>

<details>
<summary>Added Hypothesis and utterances overlay (409)</summary>

Closes https://github.com/ComPWA/compwa-org/issues/109

Preview [here](https://tensorwaves--409.org.readthedocs.build/en/409).

</details>

<details>
<summary>Explained how to pin dependencies with Conda (411)</summary>

Rewrote the installation page a bit so that it's clearer how to pin all dependencies with Conda. Preview [here](https://tensorwaves--411.org.readthedocs.build/en/411/install.html).

</details>

<details>
<summary>Illustrated how to use create_cached_function() in PWA notebook (412)</summary>

Added an example of how to use [`create_cached_function()`](https://tensorwaves--412.org.readthedocs.build/en/412/api/tensorwaves.estimator.html#tensorwaves.estimator.create_cached_function) in combination with an [`Estimator`](https://tensorwaves--412.org.readthedocs.build/en/412/api/tensorwaves.estimator.html#tensorwaves.estimator.Estimator). Preview [here](https://tensorwaves--412.org.readthedocs.build/en/412/amplitude-analysis.html#simplified-procedure-create-cached-function).

</details>

<details>
<summary>Added instructions how to install from Git repository with optional dependencies (413)</summary>

Added an additional install example that shows how to install a specific branch or tag with `pip` from Git _with optional dependencies_. Preview [here](https://tensorwaves--413.org.readthedocs.build/en/413/install.html#quick-installation).

</details>

πŸ–±οΈ Developer Experience

<details>
<summary>Change upgrade cron job to bi-weekly (398 and 408)</summary>

Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

</details>

<details>
<summary>Add notebook button for Deepnote (400)</summary>

Closes https://github.com/ComPWA/repo-maintenance/issues/43

[![image](https://user-images.githubusercontent.com/29308176/149676020-8281cbb4-8cae-4e1a-a171-b451809ea993.png)](https://tensorwaves--400.org.readthedocs.build/en/400/usage.html)

</details>

<details>
<summary>Type aliases in API are now abbreviated (404)</summary>

See https://github.com/ComPWA/ampform/pull/207

Compare API [v0.4.1](https://tensorwaves.rtfd.io/en/0.4.1/api/tensorwaves.interface.html) and [preview of this PR](https://tensorwaves--404.org.readthedocs.build/en/404/api/tensorwaves.interface.html).

</details>

<details>
<summary>Installed jupyterlab-myst (405)</summary>

See [`jupyterlab-myst`](https://github.com/executablebooks/jupyterlab-myst)

</details>

<details>
<summary>Tests can now be run with specific versions of dependencies (410 and 416)</summary>

Adds a [`workflow_dispatch` with inputs](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs) that allows running all tests manually with the latest version of AmpForm installed.

[![image](https://user-images.githubusercontent.com/29308176/152698999-b9df746d-8931-4398-bede-8c07ea80c11b.png)](https://github.com/ComPWA/tensorwaves/actions/workflows/ci-tests.yml)

[![image](https://user-images.githubusercontent.com/29308176/155362608-11bc9605-2e57-4e04-9cd5-f85ed93bd58b.png)](https://github.com/ComPWA/tensorwaves/actions/workflows/ci-tests.yml)

</details>

0.4.1

_See all documentation for this version [here](https://tensorwaves.rtfd.io/en/0.4.1)._

πŸ’‘ New features

<details>
<summary>Implemented create_cached_function() (397)</summary>

Closes 358

Expression tree optimizations sketched [here](https://tensorwaves.readthedocs.io/en/0.4.0/amplitude-analysis.html#prepare-parametrized-function) have been bundled in a new function [`create_cached_function()`](https://tensorwaves--397.org.readthedocs.build/en/397/api/tensorwaves.estimator.html#tensorwaves.estimator.create_cached_function). A usage notebook can be previewed [here](https://tensorwaves--397.org.readthedocs.build/en/397/usage/caching.html).

</details>


⚠️ Interface

<details>
<summary>TensorFlow has become an optional dependency (394)</summary>

All computational backends are now optional dependencies (apart from NumPy). So for instance, to install TensorWaves with JAX, run:
shell
pip install tensorwaves[jax]

To do amplitude analysis, install with:
shell
pip install tensorwaves[jax,pwa]


</details>


πŸ› Bug fixes

<details>
<summary>Progress bar of domain generator is hidden in IntensityDistributionGenerator (396)</summary>

Closes 395

python
import ampform
import qrules
from ampform.dynamics.builder import create_relativistic_breit_wigner_with_ff
from tensorwaves.data import (
IntensityDistributionGenerator,
TFPhaseSpaceGenerator,
TFUniformRealNumberGenerator,
)
from tensorwaves.data.transform import SympyDataTransformer
from tensorwaves.function.sympy import create_parametrized_function

reaction = qrules.generate_transitions(
initial_state="J/psi(1S)",
final_state=["gamma", "pi0", "pi0"],
allowed_intermediate_particles=["f(0)"],
allowed_interaction_types=["strong", "EM"],
)

builder = ampform.get_builder(reaction)
resonances = reaction.get_intermediate_particles()
for p in resonances:
builder.set_dynamics(p.name, create_relativistic_breit_wigner_with_ff)
model = builder.formulate()

intensity = create_parametrized_function(
model.expression.doit(),
parameters=model.parameter_defaults,
backend="jax",
)
helicity_transformer = SympyDataTransformer.from_sympy(
model.kinematic_variables, backend="jax"
)

phsp_generator = TFPhaseSpaceGenerator(
initial_state_mass=reaction.initial_state[-1].mass,
final_state_masses={i: p.mass for i, p in reaction.final_state.items()},
)
data_generator = IntensityDistributionGenerator(
function=intensity,
domain_generator=phsp_generator,
domain_transformer=helicity_transformer,
)
rng = TFUniformRealNumberGenerator(seed=0)
phsp_momenta = phsp_generator.generate(1_000_000, rng)
data_momenta = data_generator.generate(100_000, rng)

![image](https://user-images.githubusercontent.com/29308176/148271814-2c0c19c6-949f-4d58-b2b0-3fd2d7b84337.png)


</details>


πŸ–±οΈ Developer Experience

<details>
<summary>Increased test coverage (393)</summary>

- Wrote some additional tests for the `tensorwaves.function` module
- [`TYPE_CHECKING`](https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING) is now [ignored](https://coverage.readthedocs.io/en/latest/excluding.html#excluding-code-from-coverage-py) in test coverage

</details>

0.4.0

_See all documentation for this specific version [here](https://tensorwaves.rtfd.io/en/0.4.0)._

TensorWaves [v0.4](https://tensorwaves.rtfd.io/en/0.4.x) has a more general interface than [v0.3](https://tensorwaves.rtfd.io/en/0.3.x). Major changes are the removal of the `Model` interface (#357) and generalization of the `data` module (392). This affects the way in which computational backend functions are created and the way in which hit-and-miss distributions are generated.

Some examples of syntax changes for an AmpForm `HelicityModel` (`model`):

**v0.4.x** (new)

python
create function and data transformer
from tensorwaves.function.sympy import create_parametrized_function

intensity = create_parametrized_function(
expression=model.expression.doit(),
parameters=model.parameter_defaults,
backend="jax",
)
helicity_transformer = SympyDataTransformer.from_sympy(
model.kinematic_variables, backend="numpy"
)

generate data
from tensorwaves.data import (
IntensityDistributionGenerator,
SympyDataTransformer,
TFPhaseSpaceGenerator,
TFUniformRealNumberGenerator,
)

phsp_generator = TFPhaseSpaceGenerator(
initial_state_mass=3.069,
final_state_masses={0: 0.0, 1: 0.135, 2: 0.135},
)
data_generator = IntensityDistributionGenerator(
domain_generator=phsp_generator,
function=intensity,
domain_transformer=helicity_transformer,
)
rng = TFUniformRealNumberGenerator(seed=0)
phsp = phsp_generator.generate(100_000, rng)
data = data_generator.generate(10_000, rng)


_Note that this works for general SymPy expressions: there is no AmpForm dependency._ See [this page](https://tensorwaves.readthedocs.io/en/0.4.x/usage.html).

**v0.3.x** (old)

python
from tensorwaves.model import LambdifiedFunction, SympyModel

create function and data transformer
sympy_model = SympyModel(
expression=model.expression.doit(),
parameters=model.parameter_defaults,
)
intensity = LambdifiedFunction(sympy_model, backend="jax")
helicity_transformer = HelicityTransformer(model.adapter)

generate data
from tensorwaves.data import TFUniformRealNumberGenerator, generate_data, generate_phsp
from tensorwaves.data.transform import HelicityTransformer

rng = TFUniformRealNumberGenerator(seed=0)
phsp = generate_phsp(
size=100_000,
initial_state_mass=3.069,
final_state_masses={0: 0.0, 1: 0.135, 2: 0.135},
random_generator=rng,
)
data = generate_data(
size=10_000,
initial_state_mass=3.069,
final_state_masses={0: 0.0, 1: 0.135, 2: 0.135},
data_transformer=helicity_transformer,
intensity=intensity,
random_generator=rng,
)


πŸ’‘ New features

<details>
<summary>Implemented chi-squared estimator (387)</summary>

Also includes improvements to the documentation of `estimator` module.

</details>

<details>
<summary>Implemented get_source_code function (378)</summary>

Closes 323

- Added a convenience function `tensorwaves.function.get_source_code()`
- Added read-only properties `function` and `argument_order` to `ParametrizedBackendFunction` (parallels `attrs`-decorated `PositionalArgumentFunction` class).
- `PositionalArgumentFunction` is now used internally in `ParametrizedBackendFunction` (simplifies its `__call__()` method).
- Symbols are not force-dummified anymore if `use_cse=False`

</details>

<details>
<summary>SciPy now works with TF (360)</summary>

</details>

<details>
<summary>Import optimizers directly from the tensorwaves.optimizer module (360)</summary>

It's now possible to do

python
from tensorwaves.optimizer import Minuit2


instead of

python
from tensorwaves.optimizer.minuit import Minuit2


</details>

⚠️ Interface

<details>
<summary>Adapted implementation to AmpForm v0.12.x (345)</summary>

Adapts the `data` module implementation so that it can work with [AmpForm v0.12.x](https://github.com/ComPWA/ampform/releases/tag/0.12.0). Closes https://github.com/ComPWA/ampform/issues/182.

Some major changes:

- Keys in a `DataSample` are now `str` only, not `int`. This means that momentum samples have keys `"p0"`, `"p1"`, etc. instead of `0`, `1`. This is in accordance with the `Symbol` names used in AmpForm's `HelicityModel.kinematic_variables`.
- Added a function `create_function()` that creates a `PositionalArgumentFunction`. This is a `Function` without parameters (compare `ParametrizedFunction`). The function and related class is used in the `DataTransformer` implementation, which doesn't need parameters.
- Data conversion can now be done with different back-ends.

</details>

<details>
<summary>Removed Model interface (357)</summary>

This PR removes the `Model` interface and related implementations. The interface was introduced with the idea to implement different types of expression trees later on (see [ADR-001](https://compwa-org.readthedocs.io/en/stable/adr/001.html)), but this seems to be a premature optimisation. For now, the `Function` interface suffices: `Function` instances can be created through specific functions.

Some major changes:

- The `Model` interface and its implementation `SympyModel` have been removed
- `tensorwaves.model` has been renamed to `tensorwaves.function`
- There is no way to use `performance_optimize()` (for nowβ€”see 358)

This means that the workflow becomes:

python
helicity_model: ampform.helicity.HelicityModel
function = create_parametrized_function(
expression=helicity_model.expression.doit(),
parameters=helicity_model.parameter_defaults,
backend="numpy",
)


instead of

python
model = SympyModel(
expression=helicity_model.expression.doit(),
parameters=helicity_model.parameter_defaults,
max_complexity=max_complexity,
)
function = LambdifiedFunction(model, backend="numpy")


</details>

<details>
<summary>Created ParametrizedFunction interface (353)</summary>

The existing [`Function`](https://tensorwaves.readthedocs.io/en/0.3.7/api/tensorwaves.interface.html#tensorwaves.interface.Function) interface has too many responsibilities: it (1) converts a `DataSample` to an array or tensor and (2) distinguishes parameter variables from domain variables. This worked fine so far, because `Function` was only used when optimizing, where you need to tweak those parameters. In 345 though, we need to a `Function` that only does (1), for the conversion of one `DataSample` (four-momenta) to another `DataSample` (kinematic variables) with different back-ends.

This PR creates a new [`ParametrizedFunction`](https://tensorwaves.readthedocs.io/en/latest/api/tensorwaves.interface.html#tensorwaves.interface.ParametrizeFunction) interface that does (1) and (2) and a 'bare' [`Function`](https://tensorwaves.readthedocs.io/en/latest/api/tensorwaves.interface.html#tensorwaves.interface.Function) interface that does only (1). The input and output types of the `Function` interface are generic, so that it can be used in different types of function-like interfaces.

Related changes:

- Renamed `LambdifiedFunction` to `ParametrizedBackendFunction`.
- `DataTransformer.transform()` has become a `__call__` and `DataTransformer` derives from `Function`.
- `Estimator` also derives from `Function`: it computes an estimator value for a set of parameters.

</details>

<details>
<summary>Generalized data generation interface (392)</summary>

Large refactoring of the `data` module with the aim to generalize its hit-and-miss mechanisms to general domain `DataSample` types.

Interface changes

- **Removed `generate_data()` and `generate_phsp()` façade functions.** The new way to generate phase space and hit-and-miss data samples is:

python
from tensorwaves.data import IntensityDistributionGenerator
from tensorwaves.data.phasespace import TFPhaseSpaceGenerator
from tensorwaves.data.rng import TFUniformRealNumberGenerator

intensity: Function
helicity_transformer: SympyDataTransformer
rng = TFUniformRealNumberGenerator(seed=0)
phsp_generator = TFPhaseSpaceGenerator(
initial_state_mass=3.0969,
final_state_masses={0: 0.0, 1: 0.135, 2: 0.135},
)
data_generator = IntensityDistributionGenerator(
domain_generator=phsp_generator,
domain_transformer=helicity_transformer,
function=intensity,
)
phsp = phsp_generator.generate(100_000, rng)
data = data_generator.generate(10_000, rng)


- `UniformRealNumberGenerator` -> `RealNumberGenerator`
- `PhaseSpaceGenerator` -> `DataGenerator`
- `PhaseSpaceGenerator.setup()` has been merged into the constructor (`DataGenerator.__init__()`) and removed from the interface.
- Split old `TFPhaseSpaceGenerator` into an _unweighted_ `TFPhaseSpaceGenerator` (implements `DataGenerator`) and a `TFWeightedPhaseSpaceGenerator` (implements `WeightedDataGenerator`). `TFPhaseSpaceGenerator` can be used instead of the old `generate_phsp()` function.
- Collected RNGs under a new sub-module `data.rng`

New features

- New interface: `DataGenerator`, which does not generate weights as opposed to `FourMomentumGenerator`.
- `IntensityDistributionGenerator`, which should be used instead of `generate_data()`
- `IdentityTransformer`, which is just the identity implementation of a `DataTransformer`.
- `NumpyUniformRNG`

</details>

<details>
<summary>Simplified public backend signatures (362)</summary>

Only accepts a single `str` now.

</details>

πŸ› Bug fixes

<details>
<summary>Latest function call number is now also stored in Loadable callbacks (360)</summary>

</details>

<details>
<summary>CSVSummary writes estimator value as float (360)</summary>

</details>

<details>
<summary>use_cse argument is now correctly forwarded (375)</summary>

Fix-up to 374

Additional fixes:
* Enforce specifying `use_cse` argument in hidden functions.
* Remove `**kwargs` from lambdify functions. This helps mypy/pyright identify whether functions calls miss certain arguments.

</details>

πŸ”¨ Internal maintenance

<details>
<summary>Set minimal versions for sympy and pyyaml dependencies (383)</summary>

`sympy.lambdify()` doesn't work when SymPy is too old.

</details>

πŸ“ Documentation

<details>
<summary>Added GPU installation tips (381)</summary>

Preview here: https://tensorwaves--381.org.readthedocs.build/en/381/install.html

[![image](https://user-images.githubusercontent.com/29308176/145199806-c583ab2d-cddb-4aca-aadf-c0ca1631c746.png)](https://tensorwaves--381.org.readthedocs.build/en/381/install.html)

Additional improvements:

- Check link anchors with [`linkcheck_anchors = True`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-linkcheck_anchors).
- Removed `typing-extensions` from requirements.

</details>

<details>
<summary>Illustrated binned and unbinned fit (388)</summary>

Follow-up to 387. Generalizes the documentation with more non-PWA examples.

</details>

<details>
<summary>Merged and isolated amplitude analysis notebooks (389)</summary>

All example notebooks for amplitude analysis have been isolated under [tensorwaves.rtfd.io/en/latest/amplitude-analysis](https://tensorwaves.rtfd.io/en/latest/amplitude-analysis). Examples under **usage** show more general expressions.

Note that resource-intensive examples like the Scipy fit on an amplitude model and the fit anination have been substituted with simpler examples, which should speed up CI on the docs.

Closes 379

</details>
<details>
<summary>Added tips for expression tree optimization (390)</summary>

The amplitude analysis notebook now shows how to optimize the expression tree with SymPy, so that the fit is much faster. This also allows showing a more complicated fit, with more free parameters and larger initial offset.

</details>

πŸ–±οΈ Developer Experience

<details>
<summary>Added fast optimize test (360)</summary>

Closes 135

Adds a test under the `tests/unit` folder that fits a small model with all back-ends and optimizers plus a unit test for `generate_data`. This also helped fishing out some bugs (see [commit history](https://github.com/ComPWA/tensorwaves/pull/360/commits)).

</details>

<details>
<summary>Implemented benchmark monitoring (368)</summary>

Closes 103

Large improvements to the testing suite:

- Added benchmark tests
- If run on the main branch, the results are pushed to the [](https://github.com/ComPWA/tensorwaves/tree/benchmark-results) branch with the [continuous-benchmark](https://github.com/marketplace/actions/continuous-benchmark) action.
- The performance results per commit are visualised on [compwa.github.io/tensorwaves](https://compwa.github.io/tensorwaves).
- If run on pull request, a warning will be commented on any commit that decreases performance. Example: https://github.com/ComPWA/tensorwaves/commit/b5c1f075eff9f9b9c82e52faf22acbb81865fdc6#commitcomment-61330128
- Integration tests have been removed so that there are only unit tests (coverage of the unit tests is sufficient since 351).
- Test folder structure has been simplified: `tests/unit` moved one folder up.

</details>

Page 3 of 7

Β© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.