Skip to content
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

Add ability to disable read-write macro caching #200

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Ability to turn off read and write features in the macro cache.
10 changes: 10 additions & 0 deletions policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class Simulation:
is_over_dataset: bool = False
"""Whether this simulation is built over a dataset."""

macro_cache_read: bool = True
"""Whether to read from the macro cache."""

macro_cache_write: bool = True
"""Whether to write to the macro cache."""

def __init__(
self,
tax_benefit_system: "TaxBenefitSystem" = None,
Expand Down Expand Up @@ -1367,6 +1373,8 @@ def _get_macro_cache_value(
"""
Get the value of a variable from a cache file.
"""
if not self.macro_cache_read:
return None
with h5py.File(cache_file_path, "r") as f:
return f["values"][()]

Expand All @@ -1378,6 +1386,8 @@ def _set_macro_cache_value(
"""
Set the value of a variable in a cache file.
"""
if not self.macro_cache_write:
return None
with h5py.File(cache_file_path, "w") as f:
f.create_dataset("values", data=value)

Expand Down
Loading