Hypothesis strategies for unxt
Project description
unxt-hypothesis
Hypothesis strategies for unxt - unitful quantities in JAX.
This package provides Hypothesis
strategies for generating unxt objects for for property-based testing.
Installation
uv add unxt-hypothesis
Usage
from hypothesis import given
import unxt_hypothesis as ust
@given(q=ust.quantities(unit="km/s"))
def test_quantity_property(q):
# Test some property of quantities
assert q.value is not None
assert q.unit is not None
@given(u=ust.units("length"))
def test_unit_property(u):
# Test some property of units
assert u is not None
@given(sys=ust.unitsystems("m", "s", "kg", "rad"))
def test_unitsystem_property(sys):
# Test some property of unit systems
assert len(sys) == 4
Custom strategies
You can customize the strategies:
from hypothesis import strategies as st
import unxt as u
import unxt_hypothesis as ust
# Generate quantities with specific shapes
@given(q=ust.quantities(unit="m", shape=st.just((3, 3))))
def test_matrix_quantity(q):
assert q.shape == (3, 3)
# Generate quantities with specific dimensions
@given(q=ust.quantities(unit=ust.units("length")))
def test_length_quantity(q):
assert u.dimension_of(q) == u.dimension("length")
API
quantities(draw, *, shape=None, dtype=None, unit=None)
Generate random Quantity objects.
Parameters:
draw: Hypothesis draw functionshape: Strategy for array shapes (optional, defaults to small arrays)dtype: Strategy for array dtypes (optional, defaults to float32)unit: Strategy for unit strings (optional, defaults to common units)
Returns: A unxt.Quantity instance
units(draw, dimension=None, *, max_complexity=2, allow_non_integer_powers=False)
Generate random Unit objects.
Parameters:
draw: Hypothesis draw functiondimension: Physical dimension (optional, e.g.,"length","velocity")max_complexity: Maximum complexity of compound units (default: 2)allow_non_integer_powers: Allow non-integer powers (default: False)
Returns: A unxt.AbstractUnit instance
unitsystems(*units)
Generate random UnitSystem objects.
Parameters:
*units: Variable number of unit specifications. Each can be:str: Fixed unit string (e.g.,"m","kg")unxt.AbstractUnit: Fixed unit object- Strategy: A Hypothesis strategy that generates units
Returns: A unxt.AbstractUnitSystem instance
Example:
from hypothesis import given
import unxt_hypothesis as ust
# Fixed unit system
@given(sys=ust.unitsystems("m", "s", "kg", "rad"))
def test_mks_system(sys):
assert len(sys) == 4
# Varying length unit, other units fixed
@given(sys=ust.unitsystems(ust.units("length"), "s", "kg", "rad"))
def test_varying_length(sys):
assert len(sys) == 4
Documentation
For comprehensive documentation, examples, and guides, see the unxt documentation.
License
BSD 3-Clause License. See LICENSE for details.
Contributing
Contributions are welcome! Please see the main unxt repository for contributing guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unxt_hypothesis-0.1.dev410.tar.gz.
File metadata
- Download URL: unxt_hypothesis-0.1.dev410.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5c30693907e2a789708a5aa1e207d2752a9c9e8ce6e47bef412207e9b4b5e82
|
|
| MD5 |
6a07715e742d5b89c13850c7262fac10
|
|
| BLAKE2b-256 |
0eb6f5375eb83fa7cbcd10cc68252d4cd990fc1dffaf95113ce30e92c61c1378
|
Provenance
The following attestation bundles were made for unxt_hypothesis-0.1.dev410.tar.gz:
Publisher:
cd-unxt-hypothesis.yml on GalacticDynamics/unxt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unxt_hypothesis-0.1.dev410.tar.gz -
Subject digest:
e5c30693907e2a789708a5aa1e207d2752a9c9e8ce6e47bef412207e9b4b5e82 - Sigstore transparency entry: 773810368
- Sigstore integration time:
-
Permalink:
GalacticDynamics/unxt@296dd3cdaa3183a073f75095996fb24125da5ce2 -
Branch / Tag:
refs/tags/unxt-api-v1.8.0 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-unxt-hypothesis.yml@296dd3cdaa3183a073f75095996fb24125da5ce2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file unxt_hypothesis-0.1.dev410-py3-none-any.whl.
File metadata
- Download URL: unxt_hypothesis-0.1.dev410-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbdc06776fdf479e7971b1e39b1896aa81a218f8f07f17beeb112d96f6a167f0
|
|
| MD5 |
5ea0220e2aaeb8ef7e2e1d17805c47e7
|
|
| BLAKE2b-256 |
baeb192f78d8a7bbdba7b8d80fb0a6433b717492a167d8a37afe5281d098881e
|
Provenance
The following attestation bundles were made for unxt_hypothesis-0.1.dev410-py3-none-any.whl:
Publisher:
cd-unxt-hypothesis.yml on GalacticDynamics/unxt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unxt_hypothesis-0.1.dev410-py3-none-any.whl -
Subject digest:
fbdc06776fdf479e7971b1e39b1896aa81a218f8f07f17beeb112d96f6a167f0 - Sigstore transparency entry: 773810374
- Sigstore integration time:
-
Permalink:
GalacticDynamics/unxt@296dd3cdaa3183a073f75095996fb24125da5ce2 -
Branch / Tag:
refs/tags/unxt-api-v1.8.0 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-unxt-hypothesis.yml@296dd3cdaa3183a073f75095996fb24125da5ce2 -
Trigger Event:
release
-
Statement type: