Skip to content

feat: accept Into<f64> at numeric API boundaries - #1016

Merged
k88hudson-cfa merged 1 commit into
mainfrom
cdc-as81-accept-Into-f64-for-numeric-API-boundaries
Jul 27, 2026
Merged

feat: accept Into<f64> at numeric API boundaries#1016
k88hudson-cfa merged 1 commit into
mainfrom
cdc-as81-accept-Into-f64-for-numeric-API-boundaries

Conversation

@cdc-as81

Copy link
Copy Markdown
Collaborator

Summary

  • Accept impl Into<f64> in public APIs for:
    • context scheduling and simulation start times
    • time and periodic trigger builders
    • random boolean probabilities
    • periodic entity value-change tracking
  • Support wrapped numeric values in the related scheduling and tracking macros.
  • Convert values exactly once at the public boundary while retaining internal
    f64 storage.
  • Preserve existing validation and panic behavior.
  • Add documentation and regression tests using typed numeric wrappers.

Motivation

Models commonly wrap numeric values in domain-specific types, such as validated
probabilities or sortable model times. These changes allow callers to pass such
types directly without manually converting them to f64.

Existing f64 call sites remain source-compatible.

@cdc-as81 cdc-as81 linked an issue Jul 21, 2026 that may be closed by this pull request
@github-actions

Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.5 ± 0.0 3.4 3.6 1.00 ± 0.02
large_sir::baseline_households 3.5 ± 0.0 3.4 3.5 1.00
large_sir::entities 7.7 ± 0.1 7.5 7.9 2.22 ± 0.03
large_sir::households 7.4 ± 0.1 7.3 7.8 2.15 ± 0.03

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sampling sampling_single_known_length_entities 13.864% 11.853% 15.839%
sample_entity sample_entity_single_property_unindexed 100000 9.876% 9.680% 10.046%
algorithm_benches algorithm_sampling_single_known_length 8.541% 3.174% 14.304%
sampling count_and_sampling_single_known_length_entities 8.010% 6.669% 9.408%
examples example-births-deaths 6.235% 5.965% 6.484%
counts single_property_indexed_entities 5.543% 2.232% 9.770%
counts reindex_after_adding_more_entities 5.267% 4.807% 5.696%
sample_entity sample_entity_single_property_unindexed 10000 4.178% 3.580% 4.771%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti 3.836% 3.483% 4.262%
examples example-basic-infection 2.681% 2.020% 3.360%
indexing with_query_results_multiple_individually_indexed_properties_enti 2.194% 1.636% 2.565%
large_dataset bench_query_population_derived_property_entities 1.724% 1.317% 2.132%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
sampling sampling_single_unindexed_concrete_plus_derived_entities -32.976% -33.158% -32.793%
sample_entity sample_entity_single_property_indexed 10000 -13.403% -15.322% -11.135%
large_dataset bench_filter_unindexed_entity -12.787% -15.840% -9.616%
sample_entity sample_entity_whole_population 1000 -12.326% -16.133% -8.192%
sample_entity sample_entity_whole_population 100000 -10.839% -13.227% -8.505%
sample_entity sample_entity_single_property_indexed 100000 -9.121% -10.332% -7.859%
large_dataset bench_query_population_indexed_property_entities -9.074% -9.738% -8.368%
sample_entity sample_entity_single_property_indexed 1000 -7.730% -9.256% -6.122%
sample_entity sample_entity_whole_population 10000 -6.002% -8.401% -3.373%
large_dataset bench_match_entity -4.783% -6.424% -3.501%
large_dataset bench_filter_indexed_entity -4.468% -6.015% -2.719%
indexing query_people_multiple_individually_indexed_properties_entities -2.528% -2.740% -2.299%
sample_entity sample_entity_multi_property_indexed 10000 -2.385% -3.495% -1.153%
algorithm_benches algorithm_sampling_multiple_known_length -1.989% -2.804% -1.163%
indexing with_query_results_single_indexed_property_entities -1.984% -2.396% -1.615%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
indexing query_people_count_multiple_individually_indexed_properties_enti -1.704% -2.433% -0.554%
sample_entity sample_entity_multi_property_indexed 1000 -1.511% -2.797% -0.162%
sample_entity sample_entity_multi_property_indexed 100000 -1.383% -2.421% -0.350%
indexing query_people_count_single_indexed_property_entities -1.287% -1.609% -0.802%
sampling sampling_multiple_known_length_entities 0.968% 0.697% 1.247%
sample_entity sample_entity_single_property_unindexed 1000 0.953% 0.622% 1.277%
sampling sampling_multiple_l_reservoir_entities 0.929% 0.690% 1.179%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.885% -1.230% -0.563%
indexing query_people_indexed_multi-property_entities 0.825% -0.507% 2.082%
counts single_property_unindexed_entities 0.651% -0.102% 1.374%
large_dataset bench_query_population_multi_unindexed_entities 0.552% 0.115% 1.175%
counts concrete_plus_derived_unindexed_entities -0.460% -1.334% 0.445%
counts index_after_adding_entities 0.412% 0.151% 0.691%
large_dataset bench_query_population_property_entities -0.404% -1.271% 0.171%
counts multi_property_indexed_entities 0.229% -0.569% 1.174%
indexing query_people_count_indexed_multi-property_entities 0.196% -0.215% 0.602%
sampling sampling_multiple_unindexed_entities 0.194% 0.055% 0.403%
algorithm_benches algorithm_sampling_multiple_l_reservoir 0.191% -0.361% 0.798%
sampling sampling_single_unindexed_entities -0.151% -0.285% -0.033%
algorithm_benches algorithm_sampling_single_l_reservoir 0.127% -0.274% 0.711%
counts multi_property_unindexed_entities -0.120% -1.343% 1.563%
indexing with_query_results_indexed_multi-property_entities -0.106% -0.427% 0.392%
indexing query_people_single_indexed_property_entities -0.066% -0.285% 0.262%
large_dataset bench_query_population_multi_indexed_entities 0.062% -0.295% 0.358%
sampling sampling_single_l_reservoir_entities 0.004% -0.587% 0.488%
Not Compared (no baseline yet)
Group Bench Reason
(none)

github-actions Bot added a commit that referenced this pull request Jul 21, 2026

@k88hudson-cfa k88hudson-cfa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. I filed #1019 as a follow up, although it's very minor

@k88hudson-cfa
k88hudson-cfa merged commit 5f01589 into main Jul 27, 2026
22 checks passed
@k88hudson-cfa
k88hudson-cfa deleted the cdc-as81-accept-Into-f64-for-numeric-API-boundaries branch July 27, 2026 17:34
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.

Accept Into<f64> for numeric API boundaries

3 participants