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

Fix/resolve warnings #130

Merged
merged 8 commits into from
May 31, 2024
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ All notable changes to this project will be documented in this file.
### Added


### Changed

### Fixed

## [0.8.1] - 2024-05-31

### Added

- Added `PyQt6` as dev dependency to allow developers to view plots in the development environment

### Changed

- Removed the redundant function `evaluate_sample` from `sampling.py`

### Fixed

- Switched from `importlib.resources.path` to `importlib.resources.files` due to deprecation
- Removed argument name in call to `files(...)` that is changing from `package` to `anchor`
- Removed unused kwargs passed to the plotting function `contour` that generated a warning in `test_heat_model()`
- Bug that changed the model attribute `central_param` during `inference`

## [0.8.0] - 2024-03-21

Expand Down
7 changes: 3 additions & 4 deletions eulerpi/core/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ def run_emcee_sampling(
# Calculate the standard deviation of the data for each dimension
data_stdevs = calc_kernel_width(data)
sampling_dim = slice.shape[0]
central_param = model.central_param
param_limits = model.param_limits

# Initialize each walker at a Gaussian-drawn random, slightly different parameter close to the central parameter.
# compute element-wise min of the difference between the central parameter and the lower sampling limit and the difference between the central parameter and the upper sampling limit
d_min = np.minimum(
central_param - param_limits[:, 0], param_limits[:, 1] - central_param
model.central_param - model.param_limits[:, 0],
model.param_limits[:, 1] - model.central_param,
)
initial_walker_positions = central_param[slice] + d_min[slice] * (
initial_walker_positions = model.central_param[slice] + d_min[slice] * (
np.random.rand(num_walkers, sampling_dim) - 0.5
)

Expand Down
4 changes: 1 addition & 3 deletions eulerpi/core/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def evaluate_density(

"""

limits = model.param_limits

# Build the full parameter vector for evaluation based on the passed param slice and the constant central points
fullParam = model.central_param
fullParam = model.central_param.copy()
fullParam[slice] = param

# Check if the tried parameter is within the just-defined bounds and return the lowest possible density if not.
Expand Down
3 changes: 2 additions & 1 deletion eulerpi/examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
cmake_minimum_required(VERSION 3.4...3.18)
cmake_minimum_required(VERSION 3.4...3.29)
project(cpp_model LANGUAGES CXX)

find_package(Eigen3 REQUIRED)
# Maybe you have to do something linke this: sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}")

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 REQUIRED)
pybind11_add_module(cpp_model wrapper.cpp cpp_model.hpp) # Add wrapper code and all library source files

Expand Down
2 changes: 1 addition & 1 deletion eulerpi/examples/sbml/sbml_caffeine_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
) -> None:
param_ids = ["A", "B"]
timepoints = np.array([0.5, 1.0])
sbml_files = files(package="eulerpi.examples.sbml")
sbml_files = files("eulerpi.examples.sbml")
sbml_file_name = "Caffeine_2Wks_Exponential_decay.xml"
with as_file(sbml_files.joinpath(sbml_file_name)) as sbml_file:
super().__init__(
Expand Down
9 changes: 5 additions & 4 deletions eulerpi/examples/temperature/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def jacobian(self, param):

class TemperatureArtificial(Temperature, ArtificialModelInterface):
def generate_artificial_params(self, num_data_points: int = -1):
paramPath = importlib.resources.path(
"eulerpi.examples.temperature", "TemperatureArtificialParams.csv"
)
true_param_sample = np.loadtxt(paramPath, delimiter=",", ndmin=2)
param_resource = importlib.resources.files(
"eulerpi.examples.temperature"
).joinpath("TemperatureArtificialParams.csv")
with importlib.resources.as_file(param_resource) as param_file:
true_param_sample = np.loadtxt(param_file, delimiter=",", ndmin=2)
return true_param_sample


Expand Down
207 changes: 132 additions & 75 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ sphinx-rtd-theme = "^2.0.0"
myst-parser = "^3.0.1"
jupyter = "^1.0.0"
nbmake = "^1.5.3"
pyqt6 = "^6.7.0"

[build-system]
requires = ["poetry-core"]
Expand Down
35 changes: 21 additions & 14 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ def test_examples(example, inference_type):
ModelClass = getattr(module, className)
model: Model = ModelClass()

# generate artificial data if necessary
if model.is_artificial():
num_data_points = 100
params = model.generate_artificial_params(num_data_points)
data = model.generate_artificial_data(params)
else:
assert dataFileName is not None
data = importlib.resources.path(module_location, dataFileName)

# Define kwargs for inference
kwargs = {}
kwargs["inference_type"] = inference_type
Expand All @@ -137,11 +128,27 @@ def test_examples(example, inference_type):
elif inference_type == InferenceType.SPARSE_GRID:
kwargs["num_levels"] = 3

params, sim_res, densities, result_manager = inference(
model,
data,
**kwargs,
)
# generate artificial data if necessary
if model.is_artificial():
num_data_points = 100
params = model.generate_artificial_params(num_data_points)
data = model.generate_artificial_data(params)
params, sim_res, densities, result_manager = inference(
model,
data,
**kwargs,
)
else:
assert dataFileName is not None
data_resource = importlib.resources.files(module_location).joinpath(
dataFileName
)
with importlib.resources.as_file(data_resource) as data_file:
params, sim_res, densities, result_manager = inference(
model,
data_file,
**kwargs,
)

# get all keys of the params dict
full_slice_str = list(params.keys())[0]
Expand Down
21 changes: 10 additions & 11 deletions tests/test_fixed_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ def temp_name(low_T, high_T):
def test_fixed_params(temperatures):
""" """
model: Model = TemperatureWithFixedParams(*temperatures)
data = importlib.resources.path(
"eulerpi.examples.temperature", "TemperatureData.csv"
)

run_name = temp_name(*temperatures)

inference(
model,
data,
num_steps=100,
run_name=run_name,
)
data_resource = importlib.resources.files(
"eulerpi.examples.temperature"
).joinpath("TemperatureData.csv")
with importlib.resources.as_file(data_resource) as data_file:
inference(
model,
data_file,
num_steps=100,
run_name=run_name,
)
2 changes: 0 additions & 2 deletions tests/test_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def test_heat_model():
np.arange(0, 1, 0.1),
# np.arange(np.min(u), np.max(u), (np.max(u) - np.min(u)) / 8),
linewidths=2,
color="k",
extent=extent,
aspect=1,
)
ax.clabel(cset, inline=True, fmt="%1.2f", fontsize=10)

Expand Down
Loading