-
Notifications
You must be signed in to change notification settings - Fork 0
Exercise 7 #2
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
Open
annawendler
wants to merge
4
commits into
main
Choose a base branch
from
exercise_7
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Exercise 7 #2
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fbd3a1
adjust tutorial and exercise 7, comment for recommendation of vscode
annawendler 478aa74
fix link
annawendler 69f7596
workaround for windows issue, remove unused dt
annawendler 70ada04
apply workaround for advance in exercise as well
annawendler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||
| import marimo | ||||
|
|
||||
| __generated_with = "0.20.4" | ||||
| __generated_with = "0.24.0" | ||||
| app = marimo.App(width="medium") | ||||
|
|
||||
|
|
||||
|
|
@@ -128,7 +128,8 @@ def _(AgeGroup, model, np, num_age_groups): | |||
| model.parameters.CriticalPerSevere[AgeGroup(2)] = 0.25 * 2 | ||||
|
|
||||
| # Set contact frequency | ||||
| model.parameters.ContactPatterns.cont_freq_mat[0].baseline = np.ones((num_age_groups, num_age_groups)) * 10 | ||||
| model.parameters.ContactPatterns.cont_freq_mat[0].baseline = np.ones( | ||||
| (num_age_groups, num_age_groups)) * 10 | ||||
| return | ||||
|
|
||||
|
|
||||
|
|
@@ -161,8 +162,10 @@ def _(AgeGroup, model, num_age_groups, osecir, total_population_per_region): | |||
| # The population is equally distributed among the age groups | ||||
| for group in range(num_age_groups): | ||||
| # 1% of the population is initially infected, 0.5% Exposed and 0.5% in the pre- or asymptomatic state | ||||
| model.populations[AgeGroup(group), osecir.InfectionState.Exposed] = 0.005 * total_population_per_region / num_age_groups | ||||
| model.populations[AgeGroup(group), osecir.InfectionState.InfectedNoSymptoms] = 0.005 * total_population_per_region / num_age_groups | ||||
| model.populations[AgeGroup(group), osecir.InfectionState.Exposed] = 0.005 * \ | ||||
| total_population_per_region / num_age_groups | ||||
| model.populations[AgeGroup(group), osecir.InfectionState.InfectedNoSymptoms] = 0.005 * \ | ||||
| total_population_per_region / num_age_groups | ||||
| # The rest of the population is Susceptible | ||||
| model.populations.set_difference_from_group_total_AgeGroup( | ||||
| (AgeGroup(group), osecir.InfectionState.Susceptible), total_population_per_region / num_age_groups) | ||||
|
|
@@ -180,7 +183,7 @@ def _(mo): | |||
| @app.cell | ||||
| def _(graph, model, t0): | ||||
| # Add node with id 0 and copy beforehand initialized model to it | ||||
| graph.add_node(id=0, model=model, t0=t0) | ||||
| graph.add_node(id=0, model=model, t0=t0) | ||||
| return | ||||
|
|
||||
|
|
||||
|
|
@@ -198,7 +201,8 @@ def _(AgeGroup, model, num_age_groups, osecir, total_population_per_region): | |||
| for age in range(num_age_groups): | ||||
| # No infected individuals | ||||
| model.populations[AgeGroup(age), osecir.InfectionState.Exposed] = 0 | ||||
| model.populations[AgeGroup(age), osecir.InfectionState.InfectedNoSymptoms] = 0 | ||||
| model.populations[AgeGroup( | ||||
| age), osecir.InfectionState.InfectedNoSymptoms] = 0 | ||||
| # The total population is Susceptible | ||||
| model.populations.set_difference_from_group_total_AgeGroup( | ||||
| (AgeGroup(age), osecir.InfectionState.Susceptible), total_population_per_region / num_age_groups) | ||||
|
|
@@ -251,7 +255,8 @@ def _(mo): | |||
| ### Exercise | ||||
|
|
||||
| Set the mobility coefficients for `Dead` individuals to zero: | ||||
| Hint: For the first age group this can be done via `mobility_coefficients[0 * int(osecir.InfectionState.Dead) + osecir.InfectionState.Dead] = 0`. | ||||
|
|
||||
| Hint: For the first age group this can be done via `mobility_coefficients[0 * (int(osecir.InfectionState.Dead)+1) + int(osecir.InfectionState.Dead)] = 0`. | ||||
| """) | ||||
| return | ||||
|
|
||||
|
|
@@ -298,21 +303,26 @@ def _(mo): | |||
|
|
||||
|
|
||||
| @app.cell | ||||
| def _(dt_exchange, graph, osecir, t0): | ||||
| # Create graph simulation and advance until tmax | ||||
| sim = osecir.MobilitySimulation(graph, t0, dt=dt_exchange) | ||||
| def _(dt_exchange, graph, osecir, t0, tmax): | ||||
| import os | ||||
| # Silence C++ log output; it can deadlock marimo's output pipe on Windows | ||||
| devnull = os.open(os.devnull, os.O_WRONLY) | ||||
| saved_stdout, saved_stderr = os.dup(1), os.dup(2) | ||||
| os.dup2(devnull, 1) | ||||
| os.dup2(devnull, 2) | ||||
| try: | ||||
| # Create graph simulation and advance until tmax | ||||
| sim = osecir.MobilitySimulation(graph, t0, dt=dt_exchange) | ||||
| sim.advance(tmax) | ||||
| finally: | ||||
| os.dup2(saved_stdout, 1) | ||||
| os.dup2(saved_stderr, 2) | ||||
| os.close(devnull) | ||||
| os.close(saved_stdout) | ||||
| os.close(saved_stderr) | ||||
| return (sim,) | ||||
|
|
||||
|
|
||||
| @app.cell | ||||
| def _(mo): | ||||
| mo.md(r""" | ||||
| ### Exercise | ||||
| Please advance the simulation until `tmax`. | ||||
| """) | ||||
| return | ||||
|
|
||||
|
|
||||
| @app.cell | ||||
| def _(): | ||||
| # Insert code here | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or maybe even remove this entirely? |
||||
|
|
@@ -344,8 +354,10 @@ def _(mo): | |||
|
|
||||
| @app.cell | ||||
| def _(osecir, result_region0, result_region1): | ||||
| result_region0_interpolated = osecir.interpolate_simulation_result(result_region0) | ||||
| result_region1_interpolated = osecir.interpolate_simulation_result(result_region1) | ||||
| result_region0_interpolated = osecir.interpolate_simulation_result( | ||||
| result_region0) | ||||
| result_region1_interpolated = osecir.interpolate_simulation_result( | ||||
| result_region1) | ||||
| return result_region0_interpolated, result_region1_interpolated | ||||
|
|
||||
|
|
||||
|
|
@@ -368,8 +380,10 @@ def _(osecir, plt, result_region0_interpolated, result_region1_interpolated): | |||
| # Plot the number of non-symptomatically infected for both regions | ||||
| fig, ax = plt.subplots() | ||||
| time = result_array_0[0, :] | ||||
| InfectedNoSymptoms_0 = result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms), :] + result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms) + int(osecir.InfectionState.Dead) + 1, :] + result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms) + 2 * (int(osecir.InfectionState.Dead) + 1), :] | ||||
| InfectedNoSymptoms_1 = result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms), :] + result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms) + int(osecir.InfectionState.Dead) + 1, :] + result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms) + 2 * (int(osecir.InfectionState.Dead) + 1), :] | ||||
| InfectedNoSymptoms_0 = result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms), :] + result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms) + int( | ||||
| osecir.InfectionState.Dead) + 1, :] + result_array_0[1 + int(osecir.InfectionState.InfectedNoSymptoms) + 2 * (int(osecir.InfectionState.Dead) + 1), :] | ||||
| InfectedNoSymptoms_1 = result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms), :] + result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms) + int( | ||||
| osecir.InfectionState.Dead) + 1, :] + result_array_1[1 + int(osecir.InfectionState.InfectedNoSymptoms) + 2 * (int(osecir.InfectionState.Dead) + 1), :] | ||||
| ax.plot(time, InfectedNoSymptoms_0, label='Infected No Symptoms Region 1') | ||||
| ax.plot(time, InfectedNoSymptoms_1, label='Infected No Symptoms Region 2') | ||||
| ax.set_xlabel('Time [days]') | ||||
|
|
||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.