Skip to content

docs: network-hhmodel example: Separate contact from disease progression#847

Open
swo wants to merge 10 commits into
mainfrom
swo_doc_hh_example
Open

docs: network-hhmodel example: Separate contact from disease progression#847
swo wants to merge 10 commits into
mainfrom
swo_doc_hh_example

Conversation

@swo
Copy link
Copy Markdown
Contributor

@swo swo commented Apr 15, 2026

  • Don't use ixa::network, but instead instantiate edges as entities. This allows us to attach the relative rate of transmission to each edge as a property, rather than encoding the edge types as Rust types.
  • seir.rs looks for the infected people, then asks network.rs who they contact via get_contacts(). This is a nicer separation of concerns, so that the infection doesn't need to know about the contact structure.
  • Make the period of the periodic plan explicit, so that get_contacts() needs a duration argument, that says what contacts will happen over what time period.
  • Simplify how the relative rate of transmission gets passed around.
    • Don't specify a "reduction" (that divides); instead specify a relative rate (that gets multiplied).
    • Pass this in certain network::init() to simplify some test interfaces.
    • Attach the relative rate to each edge as a property.

@swo swo force-pushed the swo_doc_hh_example branch from 652087b to 64a6698 Compare April 16, 2026 18:14
github-actions Bot added a commit that referenced this pull request Apr 16, 2026
github-actions Bot added a commit that referenced this pull request Apr 16, 2026
github-actions Bot added a commit that referenced this pull request Apr 16, 2026
@github-actions

This comment was marked as off-topic.

@swo swo marked this pull request as ready for review April 16, 2026 19:19
github-actions Bot added a commit that referenced this pull request Apr 16, 2026
@github-actions

This comment was marked as off-topic.

@CDCgov CDCgov deleted a comment from github-actions Bot Apr 20, 2026
@CDCgov CDCgov deleted a comment from github-actions Bot Apr 20, 2026
@RobertJacobsonCDC
Copy link
Copy Markdown
Collaborator

Awesome! I think we've all felt the need for someone with modeling expertise to take a close look at our examples for quite some time now, so it's great that you're doing this. If you want to look over any other of the examples—or even add new ones that you think are conspicuously missing—definitely feel free to! But obviously don't feel obligated.

I'll look into the failing lints and get back to you. Sometimes they feel like a moving target...

@RobertJacobsonCDC
Copy link
Copy Markdown
Collaborator

I think it's not failing because of the lints. I think it's failing because the example never terminates: Cancelled after 365m.

github-actions Bot added a commit that referenced this pull request Apr 20, 2026
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

github-actions Bot added a commit that referenced this pull request Apr 20, 2026
@swo
Copy link
Copy Markdown
Contributor Author

swo commented Apr 21, 2026

@bbbruce -- Robert asked for another pair of eyes on this example. Would you take a look? I could do a more full-blown analysis to check for correctness if we consider the prior state to be a gold standard.

@swo
Copy link
Copy Markdown
Contributor Author

swo commented Apr 28, 2026

@bbbruce I reworked a little bit as per our discussion:

  • Don't use network module; instead define an Edge entity
  • I define Node1 and Node2 as two separate properties. (My first instinct was to define Nodes(node1, node2), but I couldn't figure out how to context.query() for only part of a tuple property, like .query(with!(Edge, Nodes(_, some_person))).)
  • I opted for directional edges, which make the queries easier (rather than unidirectional edges, which requires half the entities but makes the queries more complicated).
  • I'm having trouble figuring out how to test this. I'd like to say "look for person with data ID 826. They should have 5 contacts." That requires me to (1) query a Person, (2) get their PersonId, and (3) use that PersonId to find the relevant edges. Step 2 has me stumped. Any ideas?

@github-actions

This comment was marked as outdated.

github-actions Bot added a commit that referenced this pull request Apr 28, 2026
@swo swo marked this pull request as draft April 28, 2026 21:59
@swo swo force-pushed the swo_doc_hh_example branch from 5058da0 to 3469152 Compare April 29, 2026 13:19
@github-actions

This comment was marked as outdated.

github-actions Bot added a commit that referenced this pull request Apr 29, 2026
swo added 3 commits April 29, 2026 11:18
@swo swo marked this pull request as ready for review April 29, 2026 15:27
github-actions Bot added a commit that referenced this pull request Apr 29, 2026
@github-actions

This comment was marked as outdated.

github-actions Bot added a commit that referenced this pull request Apr 29, 2026
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

github-actions Bot added a commit that referenced this pull request Apr 29, 2026
@swo swo marked this pull request as draft April 29, 2026 15:45
github-actions Bot added a commit that referenced this pull request Apr 29, 2026
@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 2.9 ± 0.1 2.8 3.1 1.00
large_sir::entities 6.2 ± 0.1 6.0 6.5 2.16 ± 0.06

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
indexing query_people_single_indexed_property_entities 26.097% 25.286% 26.717%
indexing query_people_multiple_individually_indexed_properties_entities 12.586% 12.463% 12.752%
sample_entity sample_entity_single_property_unindexed 10000 12.131% 10.070% 14.370%
indexing with_query_results_multiple_individually_indexed_properties_enti 10.619% 10.277% 11.062%
indexing query_people_indexed_multi-property_entities 9.770% 7.945% 11.650%
indexing query_people_count_multiple_individually_indexed_properties_enti 7.018% 6.960% 7.077%
sampling sampling_multiple_known_length_entities 6.159% 5.353% 6.948%
sample_entity sample_entity_multi_property_indexed 10000 4.509% 4.080% 4.844%
sample_entity sample_entity_multi_property_indexed 1000 4.074% 3.515% 4.409%
sampling count_and_sampling_single_known_length_entities 4.058% 3.599% 4.697%
sample_entity sample_entity_multi_property_indexed 100000 3.652% 2.947% 4.229%
indexing query_people_count_indexed_multi-property_entities 3.054% 2.302% 3.857%
counts multi_property_indexed_entities 2.507% 2.295% 2.682%
sampling sampling_single_known_length_entities 2.493% 2.106% 2.809%
sample_entity sample_entity_whole_population 10000 2.310% 1.805% 2.875%
large_dataset bench_query_population_derived_property_entities 1.750% 1.630% 1.866%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
large_dataset bench_query_population_indexed_property_entities -24.900% -26.236% -23.522%
large_dataset bench_match_entity -13.400% -14.426% -12.314%
sample_entity sample_entity_single_property_unindexed 1000 -11.251% -13.909% -8.272%
sampling sampling_single_unindexed_concrete_plus_derived_entities -6.357% -6.634% -6.084%
indexing query_people_count_single_indexed_property_entities -5.106% -5.347% -4.671%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti -4.244% -4.438% -4.038%
indexing with_query_results_single_indexed_property_entities -3.906% -4.541% -3.225%
large_dataset bench_query_population_multi_indexed_entities -3.647% -3.995% -3.385%
sample_entity sample_entity_single_property_indexed 1000 -3.174% -3.728% -2.747%
sample_entity sample_entity_single_property_indexed 10000 -2.929% -3.154% -2.719%
sampling sampling_single_unindexed_entities -1.373% -1.467% -1.268%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
large_dataset bench_filter_unindexed_entity 5.015% -0.590% 10.594%
sample_entity sample_entity_single_property_indexed 100000 -1.818% -2.685% -0.828%
sample_entity sample_entity_whole_population 100000 1.456% 0.888% 2.034%
examples example-births-deaths -1.198% -1.531% -0.887%
counts index_after_adding_entities 1.148% 0.921% 1.452%
algorithm_benches algorithm_sampling_multiple_l_reservoir 1.124% 0.630% 1.556%
sampling sampling_single_l_reservoir_entities -1.081% -1.568% -0.732%
counts reindex_after_adding_more_entities 0.709% 0.512% 0.916%
sampling sampling_multiple_unindexed_entities -0.687% -0.902% -0.385%
large_dataset bench_query_population_multi_unindexed_entities -0.619% -1.574% 0.411%
indexing with_query_results_indexed_multi-property_entities -0.589% -0.956% -0.253%
sample_entity sample_entity_single_property_unindexed 100000 0.496% 0.133% 0.862%
counts concrete_plus_derived_unindexed_entities 0.445% -0.337% 0.994%
algorithm_benches algorithm_sampling_single_l_reservoir -0.402% -0.687% -0.148%
examples example-basic-infection 0.350% -0.347% 0.835%
sample_entity sample_entity_whole_population 1000 0.323% -0.490% 0.877%
sampling sampling_multiple_l_reservoir_entities -0.246% -0.313% -0.175%
counts single_property_unindexed_entities 0.181% -0.623% 1.259%
algorithm_benches algorithm_sampling_single_known_length 0.163% -0.446% 1.035%
counts single_property_indexed_entities -0.156% -0.435% 0.103%
algorithm_benches algorithm_sampling_multiple_known_length -0.151% -0.765% 0.260%
counts multi_property_unindexed_entities -0.118% -0.578% 0.374%
algorithm_benches algorithm_sampling_single_rand_reservoir 0.090% -0.323% 0.496%
large_dataset bench_filter_indexed_entity -0.067% -12.122% 14.305%
large_dataset bench_query_population_property_entities 0.038% -0.661% 0.798%

github-actions Bot added a commit that referenced this pull request Apr 30, 2026
@swo swo marked this pull request as ready for review May 12, 2026 18:07
@CDCgov CDCgov deleted a comment from github-actions Bot May 18, 2026
Comment thread examples/network-hhmodel/network.rs Outdated
Comment thread examples/network-hhmodel/main.rs Outdated
Comment thread examples/network-hhmodel/network.rs Outdated
Comment thread examples/network-hhmodel/network.rs Outdated
@swo
Copy link
Copy Markdown
Contributor Author

swo commented May 20, 2026

@RobertJacobsonCDC A few changes this round:

  • Call it relative_rate and make it clear in the readme what that means
  • Clarify some of the language and math around what the relative rate is multiplying
  • Simplify function interfaces: mostly pass the relative rate float, rather than the RelativeRate struct
  • Use the new system for implementing equality for float properties

@swo swo force-pushed the swo_doc_hh_example branch from 74cba9a to c8e61b8 Compare May 20, 2026 21:23
@swo swo requested a review from RobertJacobsonCDC May 20, 2026 21:23
@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.3 ± 0.0 3.2 3.4 1.01 ± 0.02
large_sir::baseline_households 3.2 ± 0.0 3.2 3.3 1.00
large_sir::entities 7.4 ± 0.1 7.2 7.9 2.29 ± 0.04
large_sir::households 7.1 ± 0.1 6.9 7.4 2.18 ± 0.04

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
(none)
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
(none)
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
(none)
Not Compared (no baseline yet)
Group Bench Reason
(none)

github-actions Bot added a commit that referenced this pull request May 20, 2026
github-actions Bot added a commit that referenced this pull request May 20, 2026
@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 2.7 ± 0.1 2.6 3.1 1.01 ± 0.06
large_sir::baseline_households 2.6 ± 0.1 2.6 3.5 1.00
large_sir::entities 5.3 ± 0.2 5.1 6.1 2.01 ± 0.13
large_sir::households 5.0 ± 0.1 4.9 5.3 1.91 ± 0.10

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
(none)
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
(none)
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
(none)
Not Compared (no baseline yet)
Group Bench Reason
(none)

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