Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Move all simulation contexts to WFSim (#430)
Browse files Browse the repository at this point in the history
* Move all simulation contexts to WFSim

* No need to make straxen modifications

* Bug fixes

* Loosen  requirements

* Drop 3.8, be compatible with strax(en)
  • Loading branch information
dachengx authored Jan 16, 2024
1 parent 580ca10 commit 208a0ee
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Pipi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
- name: Checkout repo
uses: actions/checkout@v3
- name: Install dependencies
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
strategy:
fail-fast: False
matrix:
python-version: [3.8, 3.9, "3.10"]
python-version: [ "3.9", "3.10" ]
test: ['coveralls', 'pytest', 'pytest_no_database']
# Only run coverage / no_database on py3.8
exclude:
- python-version: 3.9
test: pytest_no_database
- python-version: "3.10"
test: pytest_no_database
- python-version: "3.11"
test: coveralls
- python-version: "3.10"
- python-version: "3.11"
test: pytest_no_database
steps:
# Setup and installation
Expand Down Expand Up @@ -84,8 +84,8 @@ jobs:
# We need to check if we have access to the secrets, otherwise coveralls
# will yield a low coverage because of the lack of interfacing with the
# database.
HAVE_ACCESS_TO_SECTETS: ${{ secrets.RUNDB_API_URL }}
if: matrix.test == 'coveralls' && env.HAVE_ACCESS_TO_SECTETS != null
HAVE_ACCESS_TO_SECRETS: ${{ secrets.RUNDB_API_URL }}
if: matrix.test == 'coveralls' && env.HAVE_ACCESS_TO_SECRETS != null
run: |
coverage run --source=wfsim setup.py test -v
coveralls --service=github
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sphinx:
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.9"

python:
install:
Expand Down
6 changes: 3 additions & 3 deletions extra_requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
strax==1.5.5
straxen==2.1.6
epix==0.3.5
strax>=1.6.0
straxen>=2.2.0
epix>=0.3.6
git+https://github.com/XENONnT/ax_env
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'flake8',
'pytest-cov',
],
python_requires=">=3.8",
python_requires=">=3.9",
extras_require={
'docs': [
'sphinx',
Expand All @@ -44,7 +44,6 @@
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Intended Audience :: Science/Research',
Expand Down
76 changes: 74 additions & 2 deletions tests/test_contexts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import strax
import straxen
from unittest import TestCase, skipIf
from straxen.contexts import xenonnt
import wfsim
from unittest import skipIf


@skipIf(not straxen.utilix_is_configured(), 'utilix is not configured')
def test_nt_context(register=None, context=None):
Expand All @@ -15,11 +18,80 @@ def test_nt_context(register=None, context=None):
context
"""
if context is None:
context = straxen.contexts.xenonnt_simulation(cmt_run_id_sim='010000', cmt_version='global_ONLINE')
context = wfsim.contexts.xenonnt_simulation(cmt_run_id_sim='010000', cmt_version='global_ONLINE')
assert isinstance(context, strax.Context), f'{context} is not a context'

if register is not None:
assert issubclass(register, strax.Plugin), f'{register} is not a plugin'

# Search all plugins for the time field (each should have one)
context.search_field('time')


# Simulation contexts are only tested when special flags are set


class TestSimContextNT(TestCase):
@staticmethod
def context(*args, **kwargs):
kwargs.setdefault("cmt_version", "global_ONLINE")
return wfsim.contexts.xenonnt_simulation(*args, **kwargs)

@skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_nt_sim_context_main(self):
st = self.context(cmt_run_id_sim="008000")
st.search_field("time")

@skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_nt_sim_context_alt(self):
"""Some examples of how to run with a custom WFSim context."""
self.context(cmt_run_id_sim="008000", cmt_run_id_proc="008001")
self.context(cmt_run_id_sim="008000", cmt_option_overwrite_sim={"elife": 1e6})

self.context(cmt_run_id_sim="008000", overwrite_fax_file_sim={"elife": 1e6})

@skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_nt_diverging_context_options(self):
"""Test diverging options. Idea is that you can use different settings for processing and
generating data, should have been handled by RawRecordsFromWFsim but is now hacked into the
xenonnt_simulation context.
Just to show how convoluted this syntax for the
xenonnt_simulation context / CMT is...
"""
self.context(
cmt_run_id_sim="008000",
cmt_option_overwrite_sim={"elife": ("elife_constant", 1e6, True)},
cmt_option_overwrite_proc={"elife": ("elife_constant", 1e5, True)},
overwrite_from_fax_file_proc=True,
overwrite_from_fax_file_sim=True,
_config_overlap={"electron_lifetime_liquid": "elife"},
)

def test_nt_sim_context_bad_inits(self):
with self.assertRaises(RuntimeError):
self.context(
cmt_run_id_sim=None,
cmt_run_id_proc=None,
)


def test_sim_context():
wfsim.contexts.xenon1t_simulation()


@skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_sim_offline_context():
wfsim.contexts.xenonnt_simulation_offline(
run_id="026000",
global_version="global_v11",
fax_config="fax_config_nt_sr0_v4.json",
)


@skipIf(not straxen.utilix_is_configured(), "No db access, cannot test!")
def test_offline():
st = xenonnt("latest")
st.provided_dtypes()

6 changes: 3 additions & 3 deletions tests/test_wfsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_sim_1T():
**conf_1t,
),
**straxen.legacy.x1t_common_config),
**straxen.legacy.contexts_1t.get_x1t_context_config(),
**straxen.legacy.get_x1t_context_config(),
)
st.register(wfsim.RawRecordsFromFax1T)
log.debug(f'Setting testing config {testing_config_1t}')
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_sim_nt_advanced(
with tempfile.TemporaryDirectory() as tempdir:
log.debug(f'Working in {tempdir}')

st = straxen.contexts.xenonnt_simulation(cmt_run_id_sim='010000',
st = wfsim.contexts.xenonnt_simulation(cmt_run_id_sim='010000',
cmt_version='global_ONLINE',
fax_config='fax_config_nt_sr0_v0.json',
_config_overlap={},)
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_sim_mc_chain():
url_data = requests.get(test_g4).content
with open('test.root', mode='wb') as f:
f.write(url_data)
st = straxen.contexts.xenonnt_simulation(cmt_run_id_sim='010000',
st = wfsim.contexts.xenonnt_simulation(cmt_run_id_sim='010000',
cmt_version='global_ONLINE',
_config_overlap={},)
st.set_config(dict(gain_model_nv="legacy-to-pe://adc_nv",
Expand Down
2 changes: 2 additions & 0 deletions wfsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

from .load_resource import *
from .utils import *

from .contexts import *
Loading

0 comments on commit 208a0ee

Please sign in to comment.