Skip to content

Commit

Permalink
Adds release action and rename package to RATpy
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenNneji committed Jun 27, 2024
1 parent a7842e6 commit 9f5c9a1
Show file tree
Hide file tree
Showing 62 changed files with 470 additions and 416 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and upload to PyPI

on:
release:
types:
- published
workflow_dispatch:

jobs:
build_wheels:
uses: RascalSoftware/python-RAT/.github/workflows/build_wheel.yml@main

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
run: |
pip install pybind11
python setup.py sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish to TestPyPi
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
12 changes: 0 additions & 12 deletions RAT/__init__.py

This file was deleted.

8 changes: 8 additions & 0 deletions RATpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from RATpy import events, models
from RATpy.classlist import ClassList
from RATpy.controls import set_controls
from RATpy.project import Project
from RATpy.run import run
from RATpy.utils import plotting

__all__ = ["ClassList", "Project", "run", "set_controls", "models", "events", "plotting"]
File renamed without changes.
4 changes: 2 additions & 2 deletions RAT/controls.py → RATpy/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import prettytable
from pydantic import BaseModel, Field, ValidationError, field_validator

from RAT.utils.custom_errors import custom_pydantic_validation_error
from RAT.utils.enums import BoundHandling, Display, Parallel, Procedures, Strategies
from RATpy.utils.custom_errors import custom_pydantic_validation_error
from RATpy.utils.enums import BoundHandling, Display, Parallel, Procedures, Strategies


@dataclass(frozen=True)
Expand Down
5 changes: 4 additions & 1 deletion RAT/events.py → RATpy/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from typing import Callable, List, Union

from RAT.rat_core import EventBridge, EventTypes, PlotEventData, ProgressEventData
from RATpy.rat_core import EventBridge, EventTypes, PlotEventData, ProgressEventData


def notify(event_type: EventTypes, data: Union[str, PlotEventData, ProgressEventData]) -> None:
Expand Down Expand Up @@ -63,5 +64,7 @@ def clear() -> None:
__event_callbacks[key] = set()


dir_path = os.path.dirname(os.path.realpath(__file__))
os.environ["RAT_PATH"] = os.path.join(dir_path, "")
__event_impl = EventBridge(notify)
__event_callbacks = {EventTypes.Message: set(), EventTypes.Plot: set(), EventTypes.Progress: set()}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import numpy as np

import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(
name="Absorption example",
Expand Down Expand Up @@ -146,4 +145,4 @@

# Run the code and plot the results
problem, results = RAT.run(problem, controls)
RAT.utils.plotting.plot_ref_sld(problem, results, True)
RAT.plotting.plot_ref_sld(problem, results, True)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import pathlib

import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(calculation="domains", model="custom xy", geometry="substrate/liquid")

Expand Down Expand Up @@ -67,4 +66,4 @@
controls = RAT.set_controls()
problem, results = RAT.run(problem, controls)

RAT.utils.plotting.plot_ref_sld(problem, results, True)
RAT.plotting.plot_ref_sld(problem, results, True)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import pathlib

import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(calculation="domains", model="custom layers", geometry="substrate/liquid")

Expand Down Expand Up @@ -44,4 +43,4 @@
controls = RAT.set_controls()

problem, results = RAT.run(problem, controls)
RAT.utils.plotting.plot_ref_sld(problem, results, True)
RAT.plotting.plot_ref_sld(problem, results, True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(calculation="domains")

Expand Down Expand Up @@ -73,4 +72,4 @@
controls = RAT.set_controls()

problem, results = RAT.run(problem, controls)
RAT.utils.plotting.plot_ref_sld(problem, results, True)
RAT.plotting.plot_ref_sld(problem, results, True)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import setup_problem

import RAT.utils.plotting
import RATpy as RAT

path = pathlib.Path(__file__).parent.resolve()

Expand All @@ -18,7 +18,7 @@
end = time.time()
print(f"Python time is: {end-start}s\n")

RAT.utils.plotting.plot_ref_sld(project, results)
RAT.plotting.plot_ref_sld(project, results)

# Matlab
project.custom_files.set_fields(0, filename="custom_bilayer.m", language="matlab", path=path)
Expand All @@ -28,7 +28,7 @@
end = time.time()
print(f"Matlab time is: {end-start}s\n")

RAT.utils.plotting.plot_ref_sld(project, results)
RAT.plotting.plot_ref_sld(project, results)

# C++
project.custom_files.set_fields(0, filename="custom_bilayer.dll", language="cpp", path=path)
Expand All @@ -38,4 +38,4 @@
end = time.time()
print(f"C++ time is: {end-start}s\n")

RAT.utils.plotting.plot_ref_sld(project, results)
RAT.plotting.plot_ref_sld(project, results)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

import RAT
import RATpy as RAT


def make_example_problem():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

import numpy as np

import RAT
import RAT.utils.plotting
import RATpy as RAT

# Start by making the class and setting it to a custom layers type:
problem = RAT.Project(name="Orso lipid example - custom XY", model="custom xy", geometry="substrate/liquid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import numpy as np

import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(name="Orso lipid example - custom layers", model="custom layers", geometry="substrate/liquid")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import numpy as np

import RAT
import RAT.utils.plotting
import RATpy as RAT

problem = RAT.Project(
name="original_dspc_bilayer",
Expand Down Expand Up @@ -356,4 +355,4 @@
controls = RAT.set_controls()

problem, results = RAT.run(problem, controls)
RAT.utils.plotting.plot_ref_sld(problem, results, True)
RAT.plotting.plot_ref_sld(problem, results, True)
File renamed without changes.
48 changes: 26 additions & 22 deletions RAT/inputs.py → RATpy/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
import pathlib
from typing import Callable, Union

import RAT
import RAT.controls
import RAT.wrappers
from RAT.rat_core import Cells, Checks, Control, Limits, Priors, ProblemDefinition
from RAT.utils.enums import Calculations, Languages, LayerModels, TypeOptions
import RATpy
import RATpy.controls
import RATpy.wrappers
from RATpy.rat_core import Cells, Checks, Control, Limits, Priors, ProblemDefinition
from RATpy.utils.enums import Calculations, Languages, LayerModels, TypeOptions


def make_input(
project: RAT.Project,
controls: Union[RAT.controls.Calculate, RAT.controls.Simplex, RAT.controls.DE, RAT.controls.NS, RAT.controls.Dream],
project: RATpy.Project,
controls: Union[
RATpy.controls.Calculate, RATpy.controls.Simplex, RATpy.controls.DE, RATpy.controls.NS, RATpy.controls.Dream
],
) -> tuple[ProblemDefinition, Cells, Limits, Priors, Control]:
"""Constructs the inputs required for the compiled RAT code using the data defined in the input project and
controls.
Expand Down Expand Up @@ -68,7 +70,7 @@ def make_input(
limits = Limits()
priors = Priors()

for class_list in RAT.project.parameter_class_lists:
for class_list in RATpy.project.parameter_class_lists:
setattr(checks, checks_field[class_list], [int(element.fit) for element in getattr(project, class_list)])
setattr(
limits,
Expand All @@ -87,11 +89,11 @@ def make_input(
priors.qzshift = []

priors.priorNames = [
param.name for class_list in RAT.project.parameter_class_lists for param in getattr(project, class_list)
param.name for class_list in RATpy.project.parameter_class_lists for param in getattr(project, class_list)
]
priors.priorValues = [
[prior_id[param.prior_type], param.mu, param.sigma]
for class_list in RAT.project.parameter_class_lists
for class_list in RATpy.project.parameter_class_lists
for param in getattr(project, class_list)
]

Expand All @@ -103,7 +105,7 @@ def make_input(
return problem, cells, limits, priors, cpp_controls


def make_problem(project: RAT.Project) -> ProblemDefinition:
def make_problem(project: RATpy.Project) -> ProblemDefinition:
"""Constructs the problem input required for the compiled RAT code.
Parameters
Expand Down Expand Up @@ -181,25 +183,25 @@ def make_problem(project: RAT.Project) -> ProblemDefinition:
problem.numberOfDomainContrasts = len(project.domain_contrasts)
problem.fitParams = [
param.value
for class_list in RAT.project.parameter_class_lists
for class_list in RATpy.project.parameter_class_lists
for param in getattr(project, class_list)
if param.fit
]
problem.fitLimits = [
[param.min, param.max]
for class_list in RAT.project.parameter_class_lists
for class_list in RATpy.project.parameter_class_lists
for param in getattr(project, class_list)
if param.fit
]
problem.otherParams = [
param.value
for class_list in RAT.project.parameter_class_lists
for class_list in RATpy.project.parameter_class_lists
for param in getattr(project, class_list)
if not param.fit
]
problem.otherLimits = [
[param.min, param.max]
for class_list in RAT.project.parameter_class_lists
for class_list in RATpy.project.parameter_class_lists
for param in getattr(project, class_list)
if not param.fit
]
Expand All @@ -209,7 +211,7 @@ def make_problem(project: RAT.Project) -> ProblemDefinition:
return problem


def make_resample(project: RAT.Project) -> list[int]:
def make_resample(project: RATpy.Project) -> list[int]:
"""Constructs the "resample" field of the problem input required for the compiled RAT code.
Parameters
Expand All @@ -226,7 +228,7 @@ def make_resample(project: RAT.Project) -> list[int]:
return [contrast.resample for contrast in project.contrasts]


def make_data_present(project: RAT.Project) -> list[int]:
def make_data_present(project: RATpy.Project) -> list[int]:
"""Constructs the "dataPresent" field of the problem input required for the compiled RAT code.
Parameters
Expand Down Expand Up @@ -282,7 +284,7 @@ def check_indices(problem: ProblemDefinition) -> None:
)


def make_cells(project: RAT.Project) -> Cells:
def make_cells(project: RATpy.Project) -> Cells:
"""Constructs the cells input required for the compiled RAT code.
Note that the order of the inputs (i.e, f1 to f20) has been hard--coded into the compiled RAT code.
Expand Down Expand Up @@ -353,9 +355,9 @@ def make_cells(project: RAT.Project) -> Cells:
if custom_file.language == Languages.Python:
file_handles.append(get_python_handle(custom_file.filename, custom_file.function_name, custom_file.path))
elif custom_file.language == Languages.Matlab:
file_handles.append(RAT.wrappers.MatlabWrapper(full_path).getHandle())
file_handles.append(RATpy.wrappers.MatlabWrapper(full_path).getHandle())
elif custom_file.language == Languages.Cpp:
file_handles.append(RAT.wrappers.DylibWrapper(full_path, custom_file.function_name).getHandle())
file_handles.append(RATpy.wrappers.DylibWrapper(full_path, custom_file.function_name).getHandle())

# Populate the set of cells
cells = Cells()
Expand Down Expand Up @@ -418,7 +420,9 @@ def get_python_handle(file_name: str, function_name: str, path: Union[str, pathl


def make_controls(
controls: Union[RAT.controls.Calculate, RAT.controls.Simplex, RAT.controls.DE, RAT.controls.NS, RAT.controls.Dream],
controls: Union[
RATpy.controls.Calculate, RATpy.controls.Simplex, RATpy.controls.DE, RATpy.controls.NS, RATpy.controls.Dream
],
checks: Checks,
) -> Control:
"""Converts the controls object to the format required by the compiled RAT code.
Expand All @@ -436,7 +440,7 @@ def make_controls(
The controls object used in the compiled RAT code.
"""
full_controls = RAT.controls.Controls(**controls.model_dump())
full_controls = RATpy.controls.Controls(**controls.model_dump())
cpp_controls = Control()

cpp_controls.procedure = full_controls.procedure
Expand Down
2 changes: 1 addition & 1 deletion RAT/models.py → RATpy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator

from RAT.utils.enums import BackgroundActions, Hydration, Languages, Priors, TypeOptions
from RATpy.utils.enums import BackgroundActions, Hydration, Languages, Priors, TypeOptions

try:
from enum import StrEnum
Expand Down
Loading

0 comments on commit 9f5c9a1

Please sign in to comment.