Skip to content

Commit

Permalink
#17 no expires olution when setting DPs, compute on collection
Browse files Browse the repository at this point in the history
  • Loading branch information
funkchaser committed May 1, 2024
1 parent 6f770c6 commit cf42081
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/aixd_grasshopper/generate_dataset_rhinoscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import rhinoscriptsyntax as rs

from aixd_grasshopper.gh_ui_helper import TYPES
from aixd_grasshopper.gh_ui_helper import find_component_by_nickname
from aixd_grasshopper.gh_ui_helper import http_post_request
from aixd_grasshopper.gh_ui_helper import TYPES, find_component_by_nickname, http_post_request

try:
import Rhino
Expand Down Expand Up @@ -48,12 +46,16 @@ def set_values(component, vals):
vals = [vals]
for v in vals:
component.PersistentData.Append(ghtype(v))
component.ExpireSolution(True)
component.ExpireSolution(False)


def get_values(component):
component.CollectData()
component.ComputeData()

if not component.VolatileData:
return None

return [x.Value for x in component.VolatileData[0]]


Expand Down Expand Up @@ -114,9 +116,7 @@ def analysis_callback(ghdoc, dp_samples, pa_names):


def add_samples_to_dataset(samples, samples_per_file=None):
return http_post_request(
"save_samples", {"session_id": session_id, "samples": samples, "samples_per_file": samples_per_file}
)
return http_post_request("save_samples", {"session_id": session_id, "samples": samples, "samples_per_file": samples_per_file})


def combine_dp_pa(dp_samples, pa_samples):
Expand All @@ -137,9 +137,9 @@ def combine_dp_pa(dp_samples, pa_samples):
def run(n_batches, samples_per_batch):

for batch in range(n_batches):
# print("Sampling batch {}/{}...
# (samples {}..{})".format(batch+1, n_batches, batch*samples_per_batch, (batch+1)*samples_per_batch-1))
# print("Sampling batch {}/{}... (samples {}..{})".format(batch+1, n_batches, batch*samples_per_batch, (batch+1)*samples_per_batch-1))
dp_samples = generate_dp_samples(samples_per_batch)
# ghdoc.NewSolution(True)
pa_samples = calculate_pa_samples(ghdoc, dp_samples)
samples = combine_dp_pa(dp_samples, pa_samples)
add_samples_to_dataset(samples, samples_per_batch)
Expand All @@ -149,9 +149,7 @@ def run(n_batches, samples_per_batch):
# INPUT INTERFACE

n_samples = rs.GetInteger("Number of samples to generate: ", number=1000, minimum=1, maximum=None)
samples_per_batch = rs.GetInteger(
"Number of samples per batch file: ", number=n_samples / 10, minimum=1, maximum=n_samples
)
samples_per_batch = rs.GetInteger("Number of samples per batch file: ", number=n_samples / 10, minimum=1, maximum=n_samples)

n_batches = int(math.ceil(n_samples / samples_per_batch))
n_samples_final = n_batches * samples_per_batch
Expand All @@ -162,9 +160,7 @@ def run(n_batches, samples_per_batch):
dataset_name = pr["dataset_name"]
target_path = os.path.join(root, dataset_name)

print(
"\t (I will generate {} samples in {} batches and save them in {})".format(n_samples_final, n_batches, target_path)
)
print("\t (I will generate {} samples in {} batches and save them in {})".format(n_samples_final, n_batches, target_path))


run(n_batches, samples_per_batch)
Expand Down

0 comments on commit cf42081

Please sign in to comment.