Skip to content

Commit

Permalink
Merge branch 'main' into awkward-v2-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp authored Jul 9, 2024
2 parents cac00e8 + 31898bc commit b0263ee
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: pre-commit/action@v3.0.1
- name: PyLint
run: |
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.0"
rev: "v0.5.1"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def lite(session: nox.Session) -> None:
def tests(session: nox.Session) -> None:
"""Run the unit and regular tests."""
session.install("-e", ".[awkward,numba,test,test-extras,sympy]")
session.run("pytest", "--ignore", "tests/test_notebooks.py", *session.posargs)
session.run(
"pytest",
"--ignore",
"tests/test_notebooks.py",
*session.posargs,
)


@nox.session(reuse_venv=True, python=ALL_PYTHON)
Expand Down
30 changes: 12 additions & 18 deletions tests/compute/sympy/lorentz/test_Et.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,18 @@ def test_xy_eta_tau():
sympy.sqrt(sympy.Abs(-(t**2) + x**2 + y**2 + z**2))
),
)
# TODO: why won't sympy equate the expressions without double
# simplifying?
assert (
sympy.simplify(
vec.Et.simplify()
- sympy.sqrt(
(
0.25
* (x**2 + y**2)
* (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
* sympy.Abs(-(t**2) + x**2 + y**2 + z**2)
)
* sympy.exp(-2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
- 2
* sympy.sqrt(
0.25
* (x**2 + y**2)
* (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
* sympy.Abs(-(t**2) + x**2 + y**2 + z**2)
)
/ sympy.sqrt(z**2 / (x**2 + y**2) + 1)
/ (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1)
)
== 0
)
Expand Down Expand Up @@ -188,10 +184,8 @@ def test_rhophi_eta_tau():
sympy.sqrt(sympy.Abs(rho**2 - t**2 + z**2))
),
)
assert vec.Et.simplify() == sympy.sqrt(
0.25 * rho**2 * sympy.exp(2 * sympy.asinh(z / rho))
+ 0.5 * rho**2
+ 0.25 * rho**2 * sympy.exp(-2 * sympy.asinh(z / rho))
+ sympy.Abs(rho**2 - t**2 + z**2)
) / sympy.sqrt(1 + z**2 / rho**2)
assert vec.Et.simplify() == 2 * sympy.sqrt(
0.25 * rho**2 * (sympy.exp(2 * sympy.asinh(z / rho)) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / rho)) * sympy.Abs(rho**2 - t**2 + z**2)
) / (sympy.exp(2 * sympy.asinh(z / rho)) + 1)
assert vec.Et.subs(values).evalf() == pytest.approx(math.sqrt(80))
4 changes: 2 additions & 2 deletions tests/compute/sympy/lorentz/test_Et2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_xy_eta_tau():
sympy.sqrt(sympy.Abs(-(t**2) + x**2 + y**2 + z**2))
),
)
assert vec.Et2.simplify() == x**2 + y**2 + sympy.Abs(
assert vec.Et2.simplify() == 1.0 * x**2 + 1.0 * y**2 + sympy.Abs(
-(t**2) + x**2 + y**2 + z**2
) / (z**2 / (x**2 + y**2) + 1)
assert vec.Et2.subs(values).evalf() == pytest.approx(80)
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_rhophi_eta_tau():
sympy.sqrt(sympy.Abs(rho**2 - t**2 + z**2))
),
)
assert vec.Et2.simplify() == rho**2 + sympy.Abs(rho**2 - t**2 + z**2) / (
assert vec.Et2.simplify() == 1.0 * rho**2 + sympy.Abs(rho**2 - t**2 + z**2) / (
1 + z**2 / rho**2
)
assert vec.Et2.subs(values).evalf() == pytest.approx(80)
30 changes: 11 additions & 19 deletions tests/compute/sympy/lorentz/test_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,18 @@ def test_xy_eta_tau():
sympy.sqrt(sympy.Abs(-(t**2) + x**2 + y**2 + z**2))
),
)
# TODO: why won't sympy equate the expressions without double
# simplifying?
assert (
sympy.simplify(
vec.beta.simplify()
- 1.0
- 0.5
* sympy.sqrt(x**2 + y**2)
* sympy.sqrt(z**2 / (x**2 + y**2) + 1)
* (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1)
/ sympy.sqrt(
(
0.25
* (x**2 + y**2)
* (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
* sympy.Abs(-(t**2) + x**2 + y**2 + z**2)
)
* sympy.exp(-2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
0.25
* (x**2 + y**2)
* (sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2))) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / sympy.sqrt(x**2 + y**2)))
* sympy.Abs(-(t**2) + x**2 + y**2 + z**2)
)
)
== 0
Expand Down Expand Up @@ -191,13 +186,10 @@ def test_rhophi_eta_tau():
sympy.sqrt(sympy.Abs(rho**2 - t**2 + z**2))
),
)
assert vec.beta.simplify() == 1.0 * rho * sympy.sqrt(
1 + z**2 / rho**2
assert vec.beta.simplify() == 0.5 * rho * (
sympy.exp(2 * sympy.asinh(z / rho)) + 1
) / sympy.sqrt(
(
0.25 * rho**2 * (sympy.exp(2 * sympy.asinh(z / rho)) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / rho)) * sympy.Abs(rho**2 - t**2 + z**2)
)
* sympy.exp(-2 * sympy.asinh(z / rho))
0.25 * rho**2 * (sympy.exp(2 * sympy.asinh(z / rho)) + 1) ** 2
+ sympy.exp(2 * sympy.asinh(z / rho)) * sympy.Abs(rho**2 - t**2 + z**2)
)
assert vec.beta.subs(values).evalf() == pytest.approx(0.5590169943749475)
10 changes: 7 additions & 3 deletions tests/compute/sympy/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_planar_sympy():
u = t.unit()
assert type(u) is type(t)
assert type(u.azimuthal) is type(t.azimuthal)
assert u.rho == 1 if isinstance(u.rho, int) else u.rho.subs(values).evalf() == 1
assert (
u.rho == 1 if isinstance(u.rho, int) else u.rho.subs(values).evalf() == 1.0
)


def test_spatial_sympy():
Expand All @@ -49,7 +51,7 @@ def test_spatial_sympy():
assert type(u) is type(t)
assert type(u.azimuthal) is type(t.azimuthal)
assert type(u.longitudinal) is type(t.longitudinal)
assert u.mag.subs(values).evalf() == 1
assert u.mag.subs(values).evalf() == 1.0


def test_lorentz_sympy():
Expand Down Expand Up @@ -90,4 +92,6 @@ def test_lorentz_sympy():
assert type(u.azimuthal) is type(t.azimuthal)
assert type(u.longitudinal) is type(t.longitudinal)
assert type(u.temporal) is type(t.temporal)
assert u.tau == 1 if isinstance(u.tau, int) else u.tau.subs(values).evalf() == 1
assert (
u.tau == 1 if isinstance(u.tau, int) else u.tau.subs(values).evalf() == 1.0
)

0 comments on commit b0263ee

Please sign in to comment.