Repository navigation
Let extensions supply the species parameter defaults (#598) - #603
Open
gustavdelius wants to merge 1 commit into
Open
gustavdelius wants to merge 1 commit into
gustavdelius wants to merge 1 commit into
Conversation
An extension that swaps mizer's single resource for a resource system of its own leaves every auto-derived `gamma` calibrated against a resource the model no longer has. Re-calling `get_gamma_default()` cannot fix it: since #488/#577 it measures with `mizerEncounter()` on purpose, so that a default stays a property of the species parameters rather than of the model's dynamics, which also makes it structurally blind to whatever the extension installed. There was no way for the extension to hook in. Make `get_gamma_default()`, `get_f0_default()`, `get_h_default()` and `get_ks_default()` S3 generics with `.MizerParams` methods, so an extension can register its own. `get_h_default()` keeps taking a species parameter data frame through a `.default` method; its body moves to the internal `h_from_species_params()`. Registering a `get_gamma_default` method alone would still mean reimplementing the whole recalibration, because what is blind to the extension is the energy measurement, not the algebra around it. So export the measurement, `measure_avail_energy()`, as a generic too. It is the single point at which both defaults look at the prey in the model, so one method for it redirects both at the extension's resources. The rate setters call the generics, so an extension object picks the method up on every rebuild. Document the trap and the hook in the extension-package guide, with the two rules a method must follow: return a property of the species parameters, not of the dynamics, or the factor gets re-applied on every rebuild (#577, #586); and call `NextMethod()` when adding to mizer's reference state rather than replacing it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #598.
Why
newMultispeciesParams()auto-derivesgammafor any species without one, measured against whatever resource exists at construction time. An extension that later swaps in a different resource system — mizerMR'ssetMultipleResources()is the case that raised this — does not re-trigger that calculation, so those species stay calibrated against a resource the model no longer has.Re-calling
get_gamma_default()cannot fix it. Per the #488/#577 design it deliberately measures withmizerEncounter()rather thangetEncounter(), so that a default is a property of the species parameters and not of the model's dynamics. That is the right call for core mizer, but it also leaves the defaulting functions structurally blind to whatever resource or rate structure an extension has installed, with no dispatch path to hook into. mizerMR consequently carries a full parallel implementation of a calculation mizer already does.What changed
The default-calculating functions are S3 generics.
get_gamma_default(),get_f0_default(),get_h_default()andget_ks_default()are nowUseMethod()generics with.MizerParamsmethods, so an extension can registerget_gamma_default.mizerMRand daisy-chain withNextMethod().get_h_default()still accepts a species parameter data frame, now via a.defaultmethod; its body moved unchanged into the internalh_from_species_params().measure_avail_energy()is exported as a generic. Aget_gamma_defaultmethod alone would still have to reimplement everything, because the part that is blind to the extension is the energy measurement, not the algebra around it.measure_avail_energy()is the single point at whichget_gamma_default()andget_f0_default()look at the prey in the model, so one method for it redirects both defaults at the extension's resource system while thef0 → gammainversion stays in mizer. Because the rate setters call the generics, an object of the extension's class picks the method up on every rebuild — a user who handsgammaback to mizer by removing it fromgiven_species_params()gets it derived against the extension's resources from then on.Documentation. A new subsection, "But they do go through your
get_*_default()method", ininst/skills/create-extension-package/SKILL.mdstates the staleness trap, tables the five generics and what a method should return, and gives the two rules: return a property of the species parameters, not of the dynamics — folding a dynamic modulation or an additive encounter into the measurement folds it intogamma, which then determines the search volume, so it is re-applied on every rebuild (#577, #586) — and callNextMethod()when adding to mizer's reference state rather than replacing it. A pointer was added to theextend-mizerskill and an item to the author checklist;vignettes/guide-*.qmdregenerated withbuild_guides(). The help forget_gamma_default()andget_f0_default()now points at the hook, so the "does not dispatch" paragraph no longer reads as a dead end.Notes for the reviewer
assert_that(is(params, "MizerParams"))lines. Nothing was added to theupgrade-mizer-codeskill for that reason.tests/testthat/test-species_params.R, using the existingregisterExtensions/registerS3method/coerceToExtensionClasspattern from the get_gamma_default() measures available energy through the extension chain #577 tests: ameasure_avail_energymethod returning 4× the energy yields ¼ thegammaand the correspondingly higherf0; methods on all fourget_*_default()generics are honoured, including through a rebuild that recomputesh.[ FAIL 0 | WARN 0 | SKIP 49 | PASS 5146 ].devtools::check_man()clean.inst/llms.txtanddocs/llms.txtgained themeasure_avail_energy()entry by hand, in its alphabetical place in the helper section; a fullpkgdown::build_site()plusbuild_llms()would regenerate them properly.🤖 Generated with Claude Code