Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Logger/C++ Debug Mechanism Addition and Journal removal #6

Merged
merged 21 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install histogram
run: python -m pip install -e .
- name: Run tests
run: xvfb-run --server-args="-screen 0 1920x1080x24" -a python -m pytest --cov --cov-report=xml --cov-report=term --cov-config=.coveragerc
run: python -m pytest --log-cli-level=INFO --cov=src --cov-report=xml --cov-report=term
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ install:
- conda update conda
- conda config --add channels conda-forge
- conda config --add channels mcvine
- conda create -n testenv python=$TRAVIS_PYTHON_VERSION anaconda-client future pytest gxx_linux-64=7 cmake danse.ins journal pyre h5py matplotlib
- conda create -n testenv python=$TRAVIS_PYTHON_VERSION anaconda-client future pytest gxx_linux-64=7 cmake danse.ins pyre h5py matplotlib
- source activate testenv
- conda config --set anaconda_upload no
- export SRC=$PWD
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ set (PKGCLOUD_REPO "ins")
# set(DOCKER_PKGING_DEB_DIST_NAME "ubuntu")
# set(DOCKER_PKGING_DEB_DIST_VERSION "12.04")
# dependencies
set (DOCKER_PKGING_DEPS_DEB "python-numpy danse.ins journal pyre")
set (DOCKER_PKGING_DEPS_RPM "numpy danse.ins journal pyre")
set (DOCKER_PKGING_DEPS_DEB "python-numpy danse.ins pyre")
set (DOCKER_PKGING_DEPS_RPM "numpy danse.ins pyre")
set (DOCKER_PKGING_TEST_SRPM ". /opt/danse/bin/setup-danse.sh && python -c 'import histogram as p; print p'")
set (DOCKER_PKGING_TEST_RPM ${DOCKER_PKGING_TEST_SRPM})
set (DOCKER_PKGING_TEST_DEB ${DOCKER_PKGING_TEST_SRPM})
set (CONDA_PKGING_BUILD_DEPS "python numpy journal")
set (CONDA_PKGING_RUN_DEPS "python numpy danse.ins journal pyre h5py")
set (CONDA_PKGING_BUILD_DEPS "python numpy")
set (CONDA_PKGING_RUN_DEPS "python numpy danse.ins pyre h5py")

# variables
set (PYBINDING_NAME "${PROJECT_NAME}module")
Expand Down
3 changes: 1 addition & 2 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ requirements:
- versioningit
run:
- numpy
- pyre
- journal
- pyre=0.8.3

test:
imports:
Expand Down
6 changes: 3 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ dependencies:
- coverage
- cmake
- gxx_linux-64
- numpy >= 1.20.3,< 2.0
- python >=3.8
- numpy == 1.26.4
- python >=3.10
- pyre == 0.8.3
- journal==0.8.4
- matplotlib
- h5py
- pre-commit
- pytest
- pytest-cov
- pytest-xvfb
- python-build
- sphinx
- sphinx-rtd-theme
Expand Down
2 changes: 0 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ add_definitions(-DUSE_DANSE_NAMESPACE )

# include python headers
include_directories( ${PYTHON_INCLUDE_DIRS} )
# assume journal is already deployed at the same deployment prefix
# where we are going to deploy histogram
include_directories( ${DEPLOYMENT_PREFIX}/include )

# export headers from this project
Expand Down
31 changes: 6 additions & 25 deletions lib/Histogrammer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define H_HISTOGRAM_HISTOGRAMMER

#include "OutOfBound.h"
#include "journal/warning.h"

HISTOGRAM_NAMESPACE_START

Expand Down Expand Up @@ -50,10 +49,7 @@ HISTOGRAM_NAMESPACE_START
IDataType i = m_e2x( e, m_x );
if (m_fx.isOutofbound(m_x)) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer1");
warning << journal::at(__HERE__)
<< "OutOfBound: " << m_x
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
return;
}
Expand All @@ -65,10 +61,7 @@ HISTOGRAM_NAMESPACE_START
}
catch (OutOfBound & e) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer1");
warning << journal::at(__HERE__)
<< e.what()
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
}
}
Expand Down Expand Up @@ -117,10 +110,7 @@ HISTOGRAM_NAMESPACE_START
IDataType i = m_e2xy( e, m_x, m_y );
if (m_fxy.isOutofbound(m_x, m_y)) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer2");
warning << journal::at(__HERE__)
<< "OutOfBound: " << m_x << ", " << m_y
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
return;
}
Expand All @@ -132,10 +122,7 @@ HISTOGRAM_NAMESPACE_START
}
catch (OutOfBound & e) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer2");
warning << journal::at(__HERE__)
<< e.what()
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
}
}
Expand Down Expand Up @@ -186,10 +173,7 @@ HISTOGRAM_NAMESPACE_START
IDataType i = m_e2xxxx( e, m_x1, m_x2, m_x3, m_x4 );
if (m_fxxxx.isOutofbound( m_x1, m_x2, m_x3, m_x4 )) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer4");
warning << journal::at(__HERE__)
<< "OutOfBound: " << m_x1 << ", " << m_x2 << ", " << m_x3 << ", " << m_x4
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
return;
}
Expand All @@ -201,10 +185,7 @@ HISTOGRAM_NAMESPACE_START
}
catch (OutOfBound & e) {
#ifdef DEBUG
journal::warning_t warning("Histogrammer4");
warning << journal::at(__HERE__)
<< e.what()
<< journal::endl;
printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__);
#endif
}
}
Expand Down
16 changes: 3 additions & 13 deletions lib/NdArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include <vector>
#include "OutOfBound.h"

#include "journal/debug.h"


HISTOGRAM_NAMESPACE_START

/// Multiple dimensional array.
Expand Down Expand Up @@ -70,24 +67,17 @@ HISTOGRAM_NAMESPACE_START
{
m_size1D = 1;
#ifdef DEBUG
journal::debug_t debug("NdArray");
debug << journal::at(__HERE__)
<< "dimension: " << dimension() << journal::endl
<< "shape: " ;
printf("Warning NdArray %s:%d\n", __FILE__, __LINE__);
#endif

for (unsigned int i=0; i<NDimension; i++) {
m_shape[i] = shape[i];
m_size1D *= shape[i];
#ifdef DEBUG
debug
<< shape[i] << ", ";
#endif
}
#ifdef DEBUG
debug << journal::endl;
printf("Warning NdArray %s:%d -- shape[%d] = %d\n", __FILE__, __LINE__, i, shape[i]);
#endif
}
}

/// dtor.
~NdArray() { }
Expand Down
2 changes: 1 addition & 1 deletion lib/README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
c++ library for histogram-related stuff
This library depends on pyre journal.
This library used to depend on pyre journal. (It has currently been removed.)
The distributed histogram python package does not need
to contain this c++ library.

Expand Down
5 changes: 1 addition & 4 deletions lib/events2histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include "_macros.h"


#ifdef DEBUG
#include "journal/debug.h"
#endif


HISTOGRAM_NAMESPACE_START
Expand All @@ -35,7 +32,7 @@ HISTOGRAM_NAMESPACE_START
histogrammer_t & her )
{
#ifdef DEBUG
journal::debug_t debug("events2histogram");
printf("Warning events2histogram %s:%d \n", __FILE__, __LINE__);
#endif
std::for_each(events_begin, events_end, her);
}
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
name = "histogram-dev"
description = "The histogram python package provides a simple yet fundamental data structure for scientific computing histogram"
dynamic = ["version"]
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"numpy >= 1.20.3,< 2.0",
"numpy == 1.26.4"
]
license = { text = "MIT" }
keywords = ["neutrons", "histogram", "python"]
Expand Down Expand Up @@ -56,7 +56,8 @@ histogram-cli = "histogram.Histogram:main"

# pytest.ini
[tool.pytest.ini_options]

log_cli = true
log_file_format = "%(asctime)s [%(levelname)8s] (%(path)s:%(lineno)s) %(message)s"
norecursedirs = [".svn","_build"] # ignore tests in ndarray due to missing stdVector module not found

testpaths =[
Expand Down
1 change: 0 additions & 1 deletion rpm.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ BuildRequires: gcc-c++
BuildRequires: cmake > 2.6
BuildRequires: make
BuildRequires: python-devel
BuildRequires: journal

Requires: python
Requires: python-h5py
Expand Down
4 changes: 2 additions & 2 deletions src/histogram/AxisMapperCreater.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Jiao Lin Copyright (c) 2005 All rights reserved


import journal
import logging

debug = journal.debug("ins.histogram.AxisMapperCreater")
logger = logging.getLogger("Histogram")


from .EvenlyContinuousAxisMapper import EvenlyContinuousAxisMapper
Expand Down
4 changes: 2 additions & 2 deletions src/histogram/DatasetBase.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# Timothy M. Kelley Copyright (c) 2005 All rights reserved

import journal
import logging

debug = journal.debug("histogram.DatasetBase")
logger = logging.getLogger("Histogram")


msg = "class {0!s} must override {1!s}"
Expand Down
9 changes: 4 additions & 5 deletions src/histogram/DatasetContainer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python
# Timothy M. Kelley Copyright (c) 2005 All rights reserved
import logging

import journal

debug = journal.debug("histogram")
logger = logging.getLogger("Histogram")


class DatasetContainer(object):
Expand All @@ -22,7 +21,7 @@ def addDataset(self, name, id, dataset):
# 1. store by name
if name not in self._byNames:
self._byNames[name] = dataset
debug.log("{0!s} added dataset {1!s}".format(self, name))
logger.debug("{0!s} added dataset {1!s}".format(self, name))
else:
msg = "container already has dataset named {0!s}".format(name)
raise ValueError(msg)
Expand Down Expand Up @@ -79,7 +78,7 @@ def replaceDataset(self, name=None, dataset=None, id=None):
name = name or self._id2name[id]
id = id or self._name2id[name]

debug.log("{0!s} replaced dataset {1!s} (id={2!s})".format(self, name, id))
logger.debug("{0!s} replaced dataset {1!s} (id={2!s})".format(self, name, id))

self._byNames[name] = dataset
self._byIds[id] = [name, dataset]
Expand Down
10 changes: 5 additions & 5 deletions src/histogram/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## in histogram.__init__ package to create histogram.


import journal
from functools import reduce

debug = journal.debug("ins.histogram.Histogram")

import operator
from .DictAttributeCont import AttributeCont
import logging

logger = logging.getLogger("Histogram")


class Histogram(AttributeCont):
Expand Down Expand Up @@ -301,7 +301,7 @@ def __setitem__(self, indexes_or_slice, v):
if rhs is not None:
lhs[indexSlices] = rhs
else:
debug.log("indefinite behavior: setting to None")
logger.debug("indefinite behavior: setting to None")
continue

return self[indexes_or_slice]
Expand Down Expand Up @@ -763,7 +763,7 @@ def size(self):

def typeCode(self):
"""type code"""
debug.log(
logger.debug(
"Histogram %s: typecode = %s" % (self.getAttribute("name"), self._typeCode)
)
return self._typeCode
Expand Down
14 changes: 5 additions & 9 deletions src/histogram/NdArrayDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Jiao Lin Copyright (c) 2006 All rights reserved

from .DatasetBase import DatasetBase
import journal
import logging

debug = journal.debug("NdArrayDataset")
logger = logging.getLogger("Histogram")


class Dataset(DatasetBase):
Expand Down Expand Up @@ -34,8 +34,6 @@ def __init__(
attributes = attributes or {}
attributeCont = AttributeCont(dict(attributes))

# debug.log("storage = %s" % str(storage))

if shape == [] and storage is not None:
shape = storage.shape()
if shape != [] and storage is not None:
Expand All @@ -48,8 +46,6 @@ def __init__(
shape = list(shape)
_checkShape(shape)

# debug.log("shape = %s" % (storage.shape(),))

DatasetBase.__init__(self, name, unit, attributeCont, shape, storage)
return

Expand Down Expand Up @@ -442,7 +438,7 @@ def isDataset(ds):

def isCompatibleDataset(a, b):
if not isinstance(a, DatasetBase) or not isinstance(b, DatasetBase):
debug.log(
logger.debug(
"either %s or %s is not a dataset"
% (
a.__class__.__name__,
Expand All @@ -452,7 +448,7 @@ def isCompatibleDataset(a, b):
return False

if a.shape() != b.shape():
debug.log("incompatible shape: %s, %s" % (a.shape(), b.shape()))
logger.debug("incompatible shape: %s, %s" % (a.shape(), b.shape()))
return False

return True
Expand All @@ -464,7 +460,7 @@ def isUnitCompatibleDataset(a, b):
try:
a.unit() + b.unit()
except:
debug.log("incompatible units: %s, %s" % (a.unit(), b.unit()))
logger.debug("incompatible units: %s, %s" % (a.unit(), b.unit()))
return False
return True

Expand Down
Loading
Loading