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

Refactor environment #315

Merged
merged 22 commits into from
Oct 27, 2021
Merged

Refactor environment #315

merged 22 commits into from
Oct 27, 2021

Conversation

aornugent
Copy link
Collaborator

@aornugent aornugent commented Sep 13, 2021

Another incremental change toward #306.

This removes the Environment object from Parameters and passes it directly to SCM or Patch APIs as required. This is handled on the R side with what I hope are sensible defaults, but should be straightforward for users to configure.

result <- run_scm_collect(p = expand_parameters(p0, trait_matrix), 
                          env = make_environment("FF16"),
                          control = scm_base_control())

The major motivation for this was to have strategy specific variants of the FF16 Environment. See ff16_environment.cpp and plant::Water_make_environment for an example (noting that Water -> FF16w in the future).

It's tripped up something in the Stochastic Patch which isn't initialising the cohort introduction schedule correctly. Will continue to investigate. Will rebase off develop once the issue has been resolved and #314 has been merged.

Copy link
Member

@dfalster dfalster left a comment

Choose a reason for hiding this comment

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

Nice work @aornugent . Some suggestions included.

R/build_schedule.R Outdated Show resolved Hide resolved
R/ff16.R Outdated Show resolved Hide resolved
R/ff16.R Outdated Show resolved Hide resolved
R/ff16r.R Outdated Show resolved Hide resolved
R/k93.R Outdated Show resolved Hide resolved
R/stochastic.R Outdated Show resolved Hide resolved
R/strategy_support.R Outdated Show resolved Hide resolved
R/water.R Outdated Show resolved Hide resolved
inst/include/plant/parameters.h Outdated Show resolved Hide resolved
expect_identical(p2$strategies[[1]]$control, ctrl_p)
}
})
# Now overwritten in call to SCM or Patch - will need appropriate test
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to comment it out instead of delete? This will leave us wondering why it's commented out.

@aornugent
Copy link
Collaborator Author

aornugent commented Sep 27, 2021

This still requires a little house keeping, including updating documentation and some R functions as you note above.

The simplified FF16_Environment constructors work well and the differences between strategies are easily handled in the R API, with flexibility for users to override the defaults as needed.

Only canopy_rescale_usually and soil_number_of_depths are fixed/read-only. Environment rescaling only takes place in a Patch, so it may be better as a control parameter instead. I also introduced some auxilliary functions to separate environment from cohort ODE sizes (L41 of patch.h, L59 of test_patch) - this might be extended to ODE states and rates in a later PR.

Will notify once final touches have been made, but please feel free to test and review whenever convenient.

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2021

Codecov Report

❗ No coverage uploaded for pull request base (develop@195c1c5). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #315   +/-   ##
==========================================
  Coverage           ?   79.92%           
==========================================
  Files              ?       94           
  Lines              ?     8459           
  Branches           ?        0           
==========================================
  Hits               ?     6761           
  Misses             ?     1698           
  Partials           ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 195c1c5...8bd8f15. Read the comment docs.

@dfalster
Copy link
Member

dfalster commented Oct 5, 2021

Hi @aornugent

This is overall really good.

But still an important unresolved point above: #315 (comment)

We should remove default type for "make_environment()" and "scm_base_control()", and draw these from the parameters object, using something like function(p, env = make_environment(p$type), ctrl = scm_base_control(p$type)).

Otherwise it will be not very user friendly for any strategies other than "FF16"

canopy = Canopy();
};

// Light interface
Copy link
Collaborator Author

@aornugent aornugent Oct 25, 2021

Choose a reason for hiding this comment

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

@devmitch @dfalster - the unsatisfying solution was to hard code the arguments for K93_Environment. This model is only really for demonstration purposes, so the issue may rear its head again in the future.

@aornugent aornugent merged commit 1de4d47 into develop Oct 27, 2021
@aornugent aornugent deleted the refactor-environment branch October 27, 2021 00:25
@aornugent aornugent mentioned this pull request Oct 27, 2021
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.

3 participants