Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pypi-build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
python: [39, 310, 311, 312, 313]
python: [39, 310, 311, 312, 313, 314, 315]
arch: [x86, arm]
include:
- os: ubuntu-latest
Expand All @@ -42,7 +42,7 @@ jobs:
git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Build wheels
uses: pypa/cibuildwheel@v2.22.0
uses: pypa/cibuildwheel@v3.3.0
env:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ARCHS_LINUX: ${{ matrix.cibw_arch }}
Expand All @@ -65,7 +65,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
python: [39, 310, 311, 312, 313]
python: [39, 310, 311, 312, 313, 314, 315]
arch: [x86, arm]
include:
- os: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [39, 310, 311, 312, 313]
python: [39, 310, 311, 312, 313, 314, 315]
arch: [x86, arm]
include:
- os: ubuntu-latest
Expand Down
14 changes: 5 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ build/
dask-worker-space/
dist/
docs/reference/generated/
docs/reference/hillas1982.pdf
docs/*.pdf
archive
a.out
*.f
Expand Down Expand Up @@ -35,9 +37,6 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
Expand Down Expand Up @@ -186,9 +185,6 @@ dmypy.json
# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
AGENTS.md
.claude/
docs/*.md
50 changes: 50 additions & 0 deletions profile_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
"""Single-threaded line-profiling harness for CphotAng.run().

Usage:
pip install line_profiler
python profile_run.py [N] # N = batch size, default 200000

Calls run() directly (NOT __call__), so there is no dask threading. Thread
counts are pinned to 1 before numpy imports, so the profile is genuinely
single-threaded (the kernel's pow/exp are already single-threaded elementwise
ops; this just guarantees no BLAS fan-out muddies the line timings).
"""
import os
import sys

import numpy as np

from nuspacesim.simulation.eas_optical import cphotang as C
from nuspacesim.simulation.eas_optical import hillas_batch_kernel as K
from nuspacesim.simulation.eas_optical import hillas_kernel as HK
from nuspacesim.simulation.eas_optical.cphotang import CphotAng

# Pin to one thread BEFORE numpy is imported.
for _v in (
"OMP_NUM_THREADS",
"OPENBLAS_NUM_THREADS",
"MKL_NUM_THREADS",
"NUMEXPR_NUM_THREADS",
"VECLIB_MAXIMUM_THREADS",
):
os.environ[_v] = "1"

# Large single batch. run() is fully vectorized over showers (no Python loop),
# so one call processes the whole batch. Memory note: peak working set is a few
# (N, 16, 16) float32 arrays (~0.2 GB each at N=2e5) -- lower N if constrained.
N = int(sys.argv[1]) if len(sys.argv) > 1 else 200_000

rng = np.random.default_rng(20240620)
betaE = np.radians(rng.uniform(0.5, 42.0, N)) # Earth-emergence angle (rad)
alt = rng.uniform(0.0, 18.0, N) # decay altitude (km)
Eshow = rng.uniform(0.2, 8.0, N) # shower energy (100 PeV units)
lat = np.zeros(N) # cloud lat/long; cloudf=None below
long_ = np.zeros(N)

cpa = CphotAng(detector_altitude=525.0)

# Warm up (lru_cache'd leggauss, import-time costs) so they don't skew line times.
cpa.run(betaE[:1000], alt[:1000], Eshow[:1000], lat[:1000], long_[:1000])

cpa.run(betaE, alt, Eshow, lat, long_)
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
requires = ["setuptools>=65.0.0",
"setuptools_scm[toml]>=3.4",
"wheel>=0.41.0",
"pybind11>=2.8",
"numpy>1.17",
]
build-backend = "setuptools.build_meta"

Expand All @@ -16,13 +14,6 @@ parentdir_prefix_version = 'nuspacesim-'
[tool.cibuildwheel]
test-requires = "pytest"
test-command = "pytest {project}/test"

[tool.cibuildwheel.macos]
archs = ["x86_64", "universal2", "arm64"]

[tool.cibuildwheel.linux]
archs = ["x86_64"]

[tool.black]
line-length = 88
skip-string-normalization = false
Expand Down
17 changes: 6 additions & 11 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source:
git_url: {{ environ.get('FEEDSTOCK_ROOT', '..') }}

build:
skip: true # [py<37]
skip: true # [py<39]
skip: true # [win]

number: {{ build_number }}
Expand All @@ -19,29 +19,24 @@ build:
script: "{{ PYTHON }} -m pip install --no-deps . -vv"

requirements:
build:
- {{ compiler('cxx') }}
host:
- pip
- python >=3.7
- pybind11>=2.6
- python >=3.9
- setuptools >=46
- setuptools_scm[toml] >=3.4
- numpy >=1.20
- wheel
run:
- astropy
- cached_property # [py<38]
- click
- dask
- importlib_metadata # [py<38]
- importlib_resources # [py<39]
- h5py
- matplotlib
- numpy >=1.20
- numpy >=1.21
- pydantic
- rich
- python >=3.7
- python >=3.9
- scipy
- tomli-w

# Woe is us. We lack tests.
test:
Expand Down
6 changes: 6 additions & 0 deletions sample_input_file.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ enable = true
total_electron_content = 10.0
total_electron_error = 0.1

[simulation.cherenkov_quadrature]
n_nodes = 12
n_slant_sub = 8
n_energy_low = 3
n_energy_high = 8

[simulation.tau_shower]
id = "nupyprop"
etau_frac = 0.5
Expand Down
9 changes: 3 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license_files = LICENSE.txt
classifiers =
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Programming Language :: C++
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.9
Expand Down Expand Up @@ -38,9 +37,6 @@ install_requires =
rich
scipy
tomli-w
configparser;python_version<"3.8"
importlib-metadata;python_version<"3.8"
importlib-resources;python_version<"3.9"
tomli;python_version<"3.11"
python_requires = >=3.9
ext_package = nuspacesim
Expand Down Expand Up @@ -95,18 +91,19 @@ universal = 0

[tox:tox]
envlist =
py{38,39,310,311,312,313}
py{39,310,311,312,313,314,315}
docs
isolated_build = True

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312
3.13: py313
3.14: py314
3.15: py315

[testenv]
deps =
Expand Down
16 changes: 0 additions & 16 deletions setup.py

This file was deleted.

3 changes: 3 additions & 0 deletions src/nuspacesim/apps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@

import click

from nuspacesim import version

from . import create_config, run, show_plot


@click.group()
@click.version_option(version=version, prog_name="nuspacesim")
def cli():
pass

Expand Down
14 changes: 14 additions & 0 deletions src/nuspacesim/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
# from .simulation.geometry.too import *
from .simulation.spectra.spectra import Spectra
from .simulation.taus.taus import Taus
from .utils.distributed import BackgroundCluster

__all__ = ["compute"]

Expand Down Expand Up @@ -186,6 +187,12 @@ def add_meta(self, name: str, value: Any, comment: str):

logv(f"Running NuSpaceSim with Energy Spectrum ({config.simulation.spectrum})")

# The single EAS optical __call__ needs a process-based dask cluster whose
# ~2s spawn would otherwise be paid serially at that stage. Start it now, in
# the background, so the spawn overlaps the geometry/spectra/tau/decay
# stages; it's handed to eas() warm and torn down right after.
optical_cluster = BackgroundCluster() if config.detector.optical.enable else None

logv("Computing [green] Geometries.[/]")
beta_tr, thetaArr, pathLenArr, *_ = geom(
config.simulation.thrown_events, store=sw, plot=to_plot
Expand All @@ -201,6 +208,8 @@ def add_meta(self, name: str, value: Any, comment: str):
console.log(
"\t[red] WARNING: No valid events thrown! Exiting early! Check geometry![/]"
)
if optical_cluster is not None:
optical_cluster.close()
return sim

init_lat, init_long = geom.find_lat_long_along_traj(np.zeros_like(beta_tr))
Expand Down Expand Up @@ -234,10 +243,15 @@ def add_meta(self, name: str, value: Any, comment: str):
init_lat,
init_long,
cloudf=cloud,
client=optical_cluster.client(),
store=sw,
plot=to_plot,
)

# Single consumer is done; release the warm cluster immediately.
optical_cluster.close()
optical_cluster = None

logv("Computing [green] Optical Monte Carlo Integral.[/]")
mcint, mcintgeo, passEV, mcunc = geom.mcintegral(
numPEs,
Expand Down
Loading
Loading