Skip to content

Commit

Permalink
Merge pull request #241 from config-i1/Python
Browse files Browse the repository at this point in the history
Merging all Python developments so far to the main branch
  • Loading branch information
config-i1 authored Feb 12, 2025
2 parents b297926 + 5dc42f0 commit 7a670ec
Show file tree
Hide file tree
Showing 46 changed files with 12,780 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ man-roxygen
^revdep$
cran-comments.md
^CRAN-SUBMISSION$
python
src/python_examples
16 changes: 16 additions & 0 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Python CI

on:
push:
branches: [Python]
pull_request:
branches: [Python]

jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
src: "./python"
20 changes: 13 additions & 7 deletions .github/workflows/ubuntu-gcc-ubsan.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Script generated by ChatGPT

name: R Package UBSan Check

on:
pull_request:
workflow_dispatch:
branches:
- main

jobs:
ubsan-check:
Expand All @@ -27,18 +26,25 @@ jobs:
- name: Install R package dependencies
run: |
Rscript -e 'install.packages(c("remotes", "devtools", "r-lib/pkgbuild", "r-lib/pkgdown"))'
Rscript -e 'install.packages(c("remotes", "devtools", "pkgbuild", "pkgdown", "rcmdcheck"))'
Rscript -e 'remotes::install_deps(dependencies = TRUE)'
- name: Install R-devel
- name: Install R-devel with UBSan
run: |
wget https://stat.ethz.ch/R/daily/R-devel.tar.gz
tar -xzf R-devel.tar.gz
cd R-devel
./configure --enable-strict-barrier --with-ubsan --with-gcc --with-x=no
make
make -j$(nproc)
echo "R-devel installed."
- name: Verify R-devel installation
run: |
cd R-devel
./bin/R --version
./bin/Rscript -e 'sessionInfo()'
- name: Run UBSan checks
run: |
R CMD check --as-cran --use-valgrind --no-manual .
export PATH=$(pwd)/R-devel/bin:$PATH
R CMD check --as-cran --use-valgrind --no-manual --no-build-vignettes .
143 changes: 143 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,146 @@ vignettes/rsconnect
vignettes/Figs
# Rprofile
.Rprofile

########################
### python gitignore ###
########################

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

#IDEs
.vscode

# memory system file
.DS_Store

#vim swap files
*.swp
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/libs/carma"]
path = src/libs/carma
url = https://github.com/RUrlus/carma.git
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 4.1.0
Date: 2024-10-01 13:06:02 UTC
SHA: feb08010ab5a8340b3811ff3f1145ba32997cb43
Version: 4.1.1
Date: 2025-02-03 12:37:40 UTC
SHA: 6b0700643ac3905c45e0ce2c29c80865b61098c8
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: smooth
Type: Package
Title: Forecasting Using State Space Models
Version: 4.1.1.41005
Date: 2025-01-05
Version: 4.1.1
Date: 2025-02-03
Authors@R: person("Ivan", "Svetunkov", email = "[email protected]", role = c("aut", "cre"),
comment="Senior Lecturer at Centre for Marketing Analytics and Forecasting, Lancaster University, UK")
URL: https://github.com/config-i1/smooth
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smooth v4.1.1 (Release data: 2025-01-05)
smooth v4.1.1 (Release data: 2025-02-03)
=======

Changes:
Expand All @@ -10,6 +10,7 @@ Bugfixes:
* Corrected the author details in the documentation.
* reapply() would not work with bootstrap in case of negative data. Now it does.
* Added a check in adam() to make sure that model is not estimated when all parameters are provided in case of ARIMA.
* Tried to fix the issue with UBSAN, but not sure whether it worked, because it is not possible to reproduce it on my PC or github Actions... Just praying that it works.


smooth v4.1.0 (Release data: 2024-10-01)
Expand Down
9 changes: 5 additions & 4 deletions R/adamGeneral.R
Original file line number Diff line number Diff line change
Expand Up @@ -3049,10 +3049,11 @@ parametersChecker <- function(data, model, lags, formulaToUse, orders, constant=
# See if the estimation of the model is not needed (do we estimate anything?)
if(!any(c(etsModel & c(persistenceLevelEstimate, persistenceTrendEstimate,
persistenceSeasonalEstimate, phiEstimate,
(initialType!="complete") & c(initialLevelEstimate,
initialTrendEstimate,
initialSeasonalEstimate)),
arimaModel & c(arEstimate, maEstimate, (initialType!="complete") & initialEstimate & initialArimaEstimate),
all(initialType!=c("complete","backcasting")) & c(initialLevelEstimate,
initialTrendEstimate,
initialSeasonalEstimate)),
arimaModel & c(arEstimate, maEstimate,
all(initialType!=c("complete","backcasting")) & initialEstimate & initialArimaEstimate),
xregModel & c(persistenceXregEstimate, (initialType!="complete") & initialXregEstimate),
constantEstimate,
otherParameterEstimate))){
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Downloads](https://cranlogs.r-pkg.org/badges/smooth)](https://cran.r-project.org/package=smooth)
[![R-CMD-check](https://github.com/config-i1/smooth/actions/workflows/test.yml/badge.svg)](https://github.com/config-i1/smooth/actions/workflows/test.yml)

# ATTENTION: THIS IS AN EXPERIMENTAL BRANCH AIMING TO ADD A PYTHON API FOR SMOOTH!

The package _smooth_ contains several smoothing (exponential and not) functions that are used in forecasting.

![hex-sticker of the smooth package for R](https://github.com/config-i1/smooth/blob/master/man/figures/smooth-web.png?raw=true)
Expand Down
12 changes: 10 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
---
title: "Cran Comments"
author: "Ivan Svetunkov"
date: "01 October 2024"
date: "03 February 2025"
output: html_document
---

## Update
I think this should fix the issue with the clang-UBSAN, gcc-UBSAN.

Also, the suggested package `legion` has been submitted to CRAN as well, and will become available soon.


## Version
This is ``smooth`` package, v4.1.0.
This is ``smooth`` package, v4.1.1.

This is a try to fix the UBSAN issue on CRAN.

## Test environments
* local Ubuntu 24.04.1, R 4.4.1
Expand Down
56 changes: 56 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.16)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)

project(smooth VERSION 0.0.1)

if(SKBUILD)
message(STATUS "The project is built using scikit-build")
endif()

# Pybind11
find_package(pybind11 REQUIRED)

# CARMA
ADD_SUBDIRECTORY(../src/libs/carma carma)

# BLAS and LAPACK. Needed by Armadillo
find_package(BLAS)
find_package(LAPACK)
if(LAPACK_FOUND AND BLAS_FOUND)
set(lapackblas_libraries ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
else()
# IS: This is where they are on my system. This might change from one OS to another
set(lapackblas_libraries "/usr/lib/x86_64-linux-gnu/")
endif()

# Armadillo
find_package(armadillo)
IF(NOT ARMADILLO_FOUND)
set(ARMADILLO_INCLUDE_DIRS "/usr/lib/")
ENDIF()
include_directories(${ARMADILLO_INCLUDE_DIRS})

# Adam General
pybind11_add_module(_adam_general ../src/python_examples/adamGeneral.cpp)
target_include_directories(_adam_general PRIVATE ../src/python_examples/.)
target_link_libraries(_adam_general PRIVATE carma::carma ${ARMADILLO_LIBRARIES} ${lapackblas_libraries})
install(TARGETS _adam_general DESTINATION smooth/adam_general)


# Old experimental stuff by Leo
# code to add the pybind11 cpp module, look at demo project
# (https://github.com/ltsaprounis/python-cpp-experiments/tree/main) for details.
#pybind11_add_module(_my_linalg ../src/python_examples/my_linalg.cpp)

# add CARMA as a subdirectory
#add_subdirectory(../src/libs/carma build)
#target_link_libraries(_my_linalg
# PRIVATE carma::carma
# ${ARMADILLO_LIBRARIES}
#)

# install(TARGETS _my_linalg DESTINATION smooth/my_linalg)

33 changes: 33 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: all lint test install environment

SRC_DIR = smooth

lint:
flake8 $(SRC_DIR)
pydocstyle $(SRC_DIR)

test:
pytest $(SRC_DIR)

install:
pip install -e ".[dev]"

environment:
(\
echo "> Creating venv"; \
python -m venv .venv; \
source .venv/bin/activate; \
echo "> Installing local package in editable mode"; \
pip install -e ".[dev]"; \
echo "> Making venv available in jupyter notebooks"; \
python -m ipykernel install --name=$(SRC_DIR); \
jupyter kernelspec list; \
echo "> Installing pre-commit"; \
pre-commit install; \
)

clean:
echo "> Removing virtual environment"
rm -r .venv
echo "> Uninstalling from jupyter"
jupyter kernelspec uninstall $(SRC_DIR)
Loading

0 comments on commit 7a670ec

Please sign in to comment.