Skip to content

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

Draft
swo wants to merge 9 commits intomainfrom
swo_doc_hh_example
Draft

docs: network-hhmodel example: Separate contact from disease progression#847
swo wants to merge 9 commits intomainfrom
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. (Unfortunately that's a f64, which leads to some problems with properties needing to implement Hash and Eq.)
  • 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.

Separately, I'll note that it might be nice to moving away from saying that contact happens with probability $\delta t \cdot \beta$ toward something like $1-e^{-\beta \cdot \delta t}$.

@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
@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
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.0 ± 0.1 2.9 3.2 1.00
large_sir::entities 7.0 ± 0.1 6.7 7.3 2.31 ± 0.07

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti 21.871% 18.336% 25.533%
large_dataset bench_match_entity 15.860% 14.578% 17.289%
large_dataset bench_query_population_derived_property_entities 9.341% 8.591% 9.905%
large_dataset bench_query_population_indexed_property_entities 9.339% 8.990% 9.728%
counts multi_property_unindexed_entities 4.979% 3.365% 6.694%
sample_entity sample_entity_single_property_indexed 10000 4.020% 2.563% 6.466%
counts concrete_plus_derived_unindexed_entities 4.019% 1.390% 6.736%
algorithm_benches algorithm_sampling_single_l_reservoir 3.847% 3.721% 3.961%
indexing query_people_multiple_individually_indexed_properties_entities 2.944% 2.840% 3.048%
indexing query_people_indexed_multi-property_entities 2.626% 1.835% 3.450%
algorithm_benches algorithm_sampling_multiple_known_length 2.460% 2.132% 2.943%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
large_dataset bench_filter_unindexed_entity -12.235% -15.712% -8.709%
counts single_property_indexed_entities -7.091% -7.393% -6.644%
sample_entity sample_entity_whole_population 10000 -6.938% -7.251% -6.552%
sample_entity sample_entity_single_property_unindexed 1000 -5.166% -7.762% -2.130%
sampling sampling_single_known_length_entities -3.134% -3.590% -2.602%
indexing query_people_count_single_indexed_property_entities -2.534% -3.009% -2.096%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
examples example-births-deaths -13.031% -26.018% 0.517%
large_dataset bench_filter_indexed_entity -7.297% -17.500% 4.867%
examples example-basic-infection 6.740% -7.024% 19.878%
sampling sampling_multiple_l_reservoir_entities -1.281% -1.660% -0.780%
sample_entity sample_entity_single_property_indexed 1000 1.268% 0.741% 1.775%
algorithm_benches algorithm_sampling_multiple_l_reservoir 1.206% 0.796% 1.573%
sample_entity sample_entity_single_property_unindexed 10000 1.187% 0.468% 1.978%
indexing query_people_count_indexed_multi-property_entities 0.903% 0.384% 1.614%
large_dataset bench_query_population_multi_indexed_entities 0.836% 0.432% 1.203%
indexing query_people_count_multiple_individually_indexed_properties_enti -0.789% -0.953% -0.659%
counts single_property_unindexed_entities -0.780% -2.158% 0.597%
sample_entity sample_entity_single_property_indexed 100000 0.667% -0.109% 1.304%
indexing with_query_results_single_indexed_property_entities -0.638% -0.857% -0.439%
counts reindex_after_adding_more_entities 0.582% 0.268% 1.022%
sampling sampling_multiple_known_length_entities -0.541% -0.802% -0.273%
large_dataset bench_query_population_property_entities 0.493% 0.180% 0.799%
large_dataset bench_query_population_multi_unindexed_entities -0.443% -0.936% 0.116%
counts multi_property_indexed_entities 0.419% 0.151% 0.747%
sample_entity sample_entity_whole_population 1000 0.415% 0.010% 0.759%
sample_entity sample_entity_multi_property_indexed 100000 -0.407% -0.609% -0.186%
sample_entity sample_entity_multi_property_indexed 1000 0.396% 0.010% 0.861%
sample_entity sample_entity_multi_property_indexed 10000 -0.391% -0.926% 0.327%
sampling sampling_single_l_reservoir_entities -0.356% -1.122% 0.259%
algorithm_benches algorithm_sampling_single_known_length -0.275% -0.931% 0.397%
indexing with_query_results_multiple_individually_indexed_properties_enti 0.273% -0.161% 0.586%
sampling sampling_single_unindexed_concrete_plus_derived_entities 0.258% -0.042% 0.499%
sample_entity sample_entity_single_property_unindexed 100000 -0.240% -0.478% -0.028%
indexing with_query_results_indexed_multi-property_entities 0.188% -0.272% 0.683%
counts index_after_adding_entities 0.139% -0.102% 0.400%
algorithm_benches algorithm_sampling_single_rand_reservoir 0.123% -0.076% 0.395%
sampling count_and_sampling_single_known_length_entities 0.113% -0.197% 0.400%
sample_entity sample_entity_whole_population 100000 0.111% -0.200% 0.556%
sampling sampling_single_unindexed_entities 0.073% -0.022% 0.236%
sampling sampling_multiple_unindexed_entities -0.062% -0.128% 0.008%
indexing query_people_single_indexed_property_entities -0.027% -0.115% 0.047%

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%

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