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

1159 add diffusive abm and smm #1162

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jubicker
Copy link
Member

@jubicker jubicker commented Dec 12, 2024

Changes and Information

Please briefly list the changes (main added features, changed items, or corrected bugs) made:

  • add diffusive ABM (model, simulation, parameters and quadwell potential)
  • add SMM (model, simulation, parameters)
  • add tests for both models
  • add examples for both models

Merge Request - Guideline Checklist

Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.

Checks by code author

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below)
  • New code adheres to coding guidelines
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.)
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP)
  • Appropriate documentation for new functionality has been added (Doxygen in the code and Markdown files if necessary)
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.)
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease)
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.)
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

closes #1159

@jubicker jubicker linked an issue Dec 12, 2024 that may be closed by this pull request
2 tasks
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 99.52381% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.01%. Comparing base (f192ec6) to head (985bd06).

Files with missing lines Patch % Lines
cpp/models/d_abm/quad_well.h 98.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1162      +/-   ##
==========================================
+ Coverage   96.97%   97.01%   +0.03%     
==========================================
  Files         148      154       +6     
  Lines       13718    13928     +210     
==========================================
+ Hits        13303    13512     +209     
- Misses        415      416       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jubicker jubicker requested a review from reneSchm December 13, 2024 14:37
Copy link
Member

@reneSchm reneSchm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to barely document code I write under a deadline. I will continue this with more suggestions later, but feel free to edit them - or add your own documentation, there is a lot to do...

The directory structure and naming looks pretty good. I have not checked the tests yet

@@ -0,0 +1,13 @@
add_library(dabm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_library(dabm
add_library(d_abm

I would keep the underscore in the name, we keep it in other models as well.

Comment on lines +8 to +10
The operator $G$ defines the infection state adoptions and only acts on $Z$, while $L$ defines location changes, only acting on $X$. Infection state adoptions are modeled with independent Poisson processes given by adoption rate functions. Movement is modeled with independent diffusion processes. A temporal Gillespie algorithm is used for simulation.

The Model class needs an Implementation class as template argument which prvides the domain agents move and interact in. We here implemented a quadwell potential given in the class QuadWellModel, but any other suitable potential can be used as implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would point out how L and G can be found in the ABM implementation. Maybe:

Suggested change
The operator $G$ defines the infection state adoptions and only acts on $Z$, while $L$ defines location changes, only acting on $X$. Infection state adoptions are modeled with independent Poisson processes given by adoption rate functions. Movement is modeled with independent diffusion processes. A temporal Gillespie algorithm is used for simulation.
The Model class needs an Implementation class as template argument which prvides the domain agents move and interact in. We here implemented a quadwell potential given in the class QuadWellModel, but any other suitable potential can be used as implementation.
The operator $G$ defines the infection state adoptions and only acts on $Z$, while $L$ defines location changes, only acting on $X$. Infection state adoptions are modeled with independent Poisson processes given by adoption rate functions. Movement is modeled with independent diffusion processes. A temporal Gillespie algorithm is used for simulation, a direct method without rejection sampling. Therefore, $G$ and $L$ are not implemented explicitly, instead their effects are sampled via the `move` and `adoption_rate` functions, respectively.
The Model class needs an Implementation class as template argument which provides the domain agents move and interact in. We here implemented a quadwell potential given in the class QuadWellModel, but any other suitable potential can be used as implementation.

(also, a typo)

Comment on lines +29 to +47
template <class Implementation>
class Model : public Implementation
{
public:
using Implementation::Implementation;

using Implementation::adopt;
using Implementation::adoption_rate;
using Implementation::get_rng;
using Implementation::move;
using Implementation::time_point;

using Status = typename Implementation::Status;
using Agent = typename Implementation::Agent;

inline constexpr void check_constraints() const
{
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoever would write all of this without a singular comment?

Suggested change
template <class Implementation>
class Model : public Implementation
{
public:
using Implementation::Implementation;
using Implementation::adopt;
using Implementation::adoption_rate;
using Implementation::get_rng;
using Implementation::move;
using Implementation::time_point;
using Status = typename Implementation::Status;
using Agent = typename Implementation::Agent;
inline constexpr void check_constraints() const
{
}
};
/**
* @brief Wrap an implementation of a diffusive ABM so it can be run by the d_abm::Simulation.
* Uses the CRTP. See comments on using statements for expected function signatures.
* @tparam Implementation A class implementing all functions and types marked with the using keyword in Model.
*/
template <class Implementation>
class Model : public Implementation
{
public:
/// Use the constructors defined by the Implementation
using Implementation::Implementation;
/**
* @brief Set the status of an agent.
* Expected signature: `void adopt(Agent&, const Status&)`
*/
using Implementation::adopt;
/**
* @brief Calculate the current adoption rate of an agent from its status to the given one.
* Expected signature: `double adoption_rate(const Agent&, const Status&)`
*/
using Implementation::adoption_rate;
/**
* @brief Change the Position of an Agent, depending on its state, the current time and step size.
* Expected signature: `void move(const double, const double, Agent&)`
* The first argument is time, the second step size.
*/
using Implementation::move;
/**
* @brief Get the Implementations RNG.
* Expected signature: `mio::RandomNumberGenerator& get_rng()`
*/
using Implementation::get_rng;
/**
* @brief Aggregate the population by their Status for the simulation result.
* Expected signature: `Eigen::VectorXd time_point()`
*/
using Implementation::time_point;
/// @brief The status of an agent.
using Status = typename Implementation::Status;
/// @brief An agent is expected to contain at least a status and a position.
using Agent = typename Implementation::Agent;
/// @brief Empty function for compatability with MEmilio.
inline constexpr void check_constraints() const
{
}
};```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add diffusive ABM and SMM
2 participants