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

Updates for variable count and size experiments #215

Merged
merged 10 commits into from
Jan 10, 2024
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we implement an early return here for seed_list when it's None? So that we don't need to check it again in L274?


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
Loading