Skip to content

Commit

Permalink
Updates for variable count and size experiments (#215)
Browse files Browse the repository at this point in the history
* set `grid_file_out` even if file does not exist

* * calculate seed before updating base name
* return count as integer
* allow specifying seed list in the recipe

* set default value for randomness seed in recipe

* * automatically specify seeds for multiple packings
* add sphere mesh objects for tests
* add recipe for nested mesh testing

* refactor seed list processing

---------

Co-authored-by: meganrm <[email protected]>
  • Loading branch information
mogres and meganrm authored Jan 10, 2024
1 parent eb4c0fa commit 6ba5a46
Show file tree
Hide file tree
Showing 8 changed files with 1,105 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cellpack/autopack/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,8 +2173,8 @@ def pack_one_seed(
"""
Packs one seed of a recipe and returns the recipe object
"""
seed_basename = self.env.add_seed_number_to_base_name(seed_index)
seed = seed_list[seed_index]
seed = int(seed_list[seed_index])
seed_basename = self.env.add_seed_number_to_base_name(seed)
# Clear
if self.afviewer:
self.afviewer.clearFill("Test_Spheres2D")
Expand Down
6 changes: 3 additions & 3 deletions cellpack/autopack/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def __init__(self, config=None, recipe=None):
f"{self.out_folder}/{self.name}_{config['name']}_{self.version}_grid.dat"
)
if recipe.get("grid_file_path") is not None:
if os.path.isfile(recipe["grid_file_path"]):
self.grid_file_out = recipe["grid_file_path"]
self.grid_file_out = recipe["grid_file_path"]

should_load_grid_file = (
os.path.isfile(self.grid_file_out) and self.load_from_grid_file
Expand Down Expand Up @@ -1832,7 +1831,8 @@ def update_variable_ingredient_attributes(self, allIngredients):
if hasattr(ingr, "count_options") and ingr.count_options is not None:

count = get_value_from_distribution(
distribution_options=ingr.count_options
distribution_options=ingr.count_options,
return_int=True,
)
if count is not None:
ingr.count = count
Expand Down
23 changes: 23 additions & 0 deletions cellpack/autopack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,26 @@ def get_value_from_distribution(distribution_options, return_int=False):
value = int(numpy.rint(value))

return value


def get_seed_list(packing_config_data, recipe_data):
# Returns a list of seeds to use for packing
if packing_config_data["randomness_seed"] is not None:
seed_list = packing_config_data["randomness_seed"]
elif recipe_data.get("randomness_seed") is not None:
seed_list = recipe_data["randomness_seed"]
else:
seed_list = None

if isinstance(seed_list, int):
seed_list = [seed_list]

if (seed_list is not None) and (
len(seed_list) != packing_config_data["number_of_packings"]
):
base_seed = int(seed_list[0])
seed_list = [
base_seed + i for i in range(packing_config_data["number_of_packings"])
]

return seed_list
6 changes: 5 additions & 1 deletion cellpack/bin/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cellpack.autopack.loaders.config_loader import ConfigLoader
from cellpack.autopack.loaders.recipe_loader import RecipeLoader
from cellpack.autopack.loaders.analysis_config_loader import AnalysisConfigLoader
from cellpack.autopack.utils import get_seed_list

###############################################################################
log_file_path = path.abspath(path.join(__file__, "../../logging.conf"))
Expand Down Expand Up @@ -56,12 +57,15 @@ def pack(recipe, config_path=None, analysis_config_path=None):
result_file=None,
)
log.info(f"saving to {env.out_folder}")

seed_list = get_seed_list(packing_config_data, recipe_data)

analyze.doloop(
packing_config_data["number_of_packings"],
env.boundingBox,
plot_figures=packing_config_data.get("save_plot_figures", True),
show_grid=packing_config_data["show_grid_plot"],
seed_list=packing_config_data["randomness_seed"],
seed_list=seed_list,
config_name=packing_config_data["name"],
recipe_version=recipe_data["version"],
image_export_options=packing_config_data.get("image_export_options"),
Expand Down
Loading

0 comments on commit 6ba5a46

Please sign in to comment.