Skip to main content

PyPI - Version Test

vegas_params

Wrapper package for Vegas integrator.

This package allows user to define composite expressions, which can be used to:

  1. Calculate integrals using vegas algorithm
  2. Make random samples of given expressions (for MC simulation apart from vegas)

1. Installation

You can install vegas_params from PyPI:

pip install vegas_params

or directly via github link:

pip install git+https://github.com/RTESolution/vegas_params.git

2. Quickstart

Let's caluclate integral $$ \int\limits_{-1000}^{1000}dx \int\limits_{-1000}^{1000}dy ; e^{-(x^2+y^2)} $$

Here is how you can do it:

import vegas_params as vp
@vp.integral
@vp.expression(x=vp.Uniform([-1000,1000]),
            y=vp.Uniform([-1000,1000]))
def gaussian(x, y):
    return np.exp(-(x**2+y**2))

Now gaussian is a callable, where you can pass the parameters of the vegas integrator:

gaussian(nitn=20, neval=100000)
#3.13805(16) - close to expected Pi

3. Defining expressions

3.1 Basic parameters

There are basic types of expressions:

#fixed value:
c = vp.Fixed(299792458) #speed of light in vacuum in m/s
#uniform value, that will be integrated over
cos_theta = vp.Uniform([-1,1]) #cos_theta is in the given range

3.2 Concatenating parameters: collections.Concat

It's possible to concatenate the parameters using vp.collections.Concat:

#say we want to define 3 coordinates with different limits: x in [-1,1], y in [0,10] and z fixed to 0
xyz = vp.collections.Concat(vp.Uniform([-1,1]), vp.Uniform([0,10]), vp.Fixed(0))
xyz.sample(1)
# array([[-0.67329745,  5.77401635,  0.        ]])

Same concatenation can be done with | operator. Also Fixed can be omitted:

#equivalent to above
xyz = vp.Uniform([-1,1])|vp.Uniform([0,10])|0
xyz.sample(1)
#array([[-0.20342379,  0.7356486 ,  0.        ]])

3.3 Producing structured array with collections.StructArray

It's possible to make a numpy.structured_array from given parameters:

xyz = vp.collections.StructArray(x=vp.Uniform([-1,1]), y=vp.Uniform([0,10]), z=0)
data = xyz.sample(1)
#array(([-0.04495105], [1.97159299], [0.]),
# dtype=[('x', '<f8', (1,)), ('y', '<f8', (1,)), ('z', '<f8', (1,))])
data['x']
#array([-0.04495105])

3.4 General compund expressions with expression decorator

Other expressions can be defined from these components.

More complex expressions can be defined using vp.Expression class or vp.expression decorator:

@vp.expression
def product(x,y):
    return x*y
    

It's possible to also add the Jacobian factor to the expression. To do this, add self argument to function and set serlf.factor to needed value. This value will be multiplied by the expression value during the integration.

3.5 Expression utilities

There are several utilities to modify the existing expression:

  • vegas_params.utils.factor: create an expression with multiplication factor, which will affect the final integral.
  • vegas_params.utils.total: create an expression with return value=1, to make
  • vegas_params.utils.normalize_integral: create expression with the total integral normalized to given value.

The usage of these expressions is illustrated by this example:

>> import vegas_params as vp
>> from vegas_params.utils import total, factor, normalize_integral
>> x = vp.Uniform([-1,1])
>> ix =vp.integral(x)(nitn=10) 
>> print(f"\\int x dx = {ix}")

>> ix = vp.integral(total(y))(nitn=10)
>> print(f"\\int dx = {ix}")

>> xf = factor(x, value=5)
>> ixf = vp.integral(total(xf))(nitn=10)
>> print(f"5*\\int dx = {ixf}")

>> xn = normalize_integral(value=123)(x)
>> ixn = vp.integral(total(xn))(nitn=10)
>> print(f"N*\\int dx = {ixn}")

\int x dx = -7.1(9.3)e-05
\int dx = 2.000000000000000(47)
5*\int dx = 10.00000000000000(24)
Normalizing norm=2.000000000000000(47) to value=123 with norm_factor=61.5
N*\int dx = 122.9999999999997(29)

4. Sampling

The vegas_params expressions and parameters can be used not only for integration, but as random value generators.

4.1. Sampling without factor

You can ask an expression to generate a sample of given size:

data = expr.sample(size=1000)

If your expression, or it's components (the expression parameters, provided in constructor) define the factor, then a simple sample method will not take it into account.

4.2 Sampling with factor

In case you want to get a sample which is distributed according to the expression's factor, you need to use sample_with_factor method, which will iteratively generate samples and filter them, by randomly discarding the samples according to their factor values:

data = expr.sample_with_factor(size=1000)

Note that this method is iterative and much slower that sample method.

Metadata

Release files for vegas-params 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vegas-params 0.3.1
File Size Uploaded Provenance Actions
vegas_params-0.3.1.tar.gz 13.1 kB With provenance Details for vegas_params-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vegas-params 0.3.1
File Interpreter ABI Platform Actions
vegas_params-0.3.1-py3-none-any.whl Python 3 none any Details for vegas_params-0.3.1-py3-none-any.whl

Total release size: 24.8 kB

Release files / vegas_params-0.3.1.tar.gz

Download URL vegas_params-0.3.1.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a26d7a4f940e67733808228e9febc05d81ad6efe9b98f61ba50cfcff97580304
BLAKE2b-256 checksum
How to use checksums
e4b9d62a345f2fa8e6a72af561a94505c9e5eb37ff79b050eba7cbcfe6dd785c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Release files / vegas_params-0.3.1-py3-none-any.whl

Download URL vegas_params-0.3.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52cebcf24d97f0e781f8451bc4e530cf8670b90d02db9e65b482eac010e2bfeb
BLAKE2b-256 checksum
How to use checksums
e795018ba6166404f6ff0cee24cd4eff9219cdce81e988bb485794d638940cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Security for vegas-params 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vegas_params-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page