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

15 generator request revise #30

Merged
merged 7 commits into from
May 2, 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
Binary file removed docs/_images/icons/aixd_GenSampleEval.png
Binary file not shown.
Binary file removed docs/_images/icons/aixd_GenSelect.png
Binary file not shown.
Binary file added docs/_images/icons/aixd_PlotContoursRequest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 28 additions & 44 deletions docs/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Retrieves one sample from the dataset (at a given or random index) and instantia

**Outputs**

- **sample** -- Summary of the retrieved sample.
- **sample_summary** -- Summary of the retrieved sample.

DatasetSummary
--------------
Expand Down Expand Up @@ -203,53 +203,16 @@ Runs a generation campaing to create new designs using the trained model.

**Inputs**

- **requested_values** *(str)* -- List of requested values, each formatted as a string with the following format: 'variable_name:value'.
- **requested_values** *[List of (str)]* -- List of requested values, each formatted as a string with the following format: 'variable_name:value'.
- **n_designs** *(int)* -- Number of designs to generate.
- **run** *(none)* -- Set to True to start the generation process.
- **generate** *(bool)* -- Set to True to start the generation process.
- **clear** *(bool)* -- Forget the previously generated designs.
- **pick_previous** *(bool)* -- Iterate backward through the list of generated designs, instantiate the previous sample.
- **pick_next** *(bool)* -- Iterate forward through the list of generated designs, instantiate the next sample.

**Outputs**

- **predicions** -- List of generated designs.

GenSampleEval
-------------
.. image:: _images/icons/aixd_GenSampleEval.png
:align: left
:height: 24
:width: 24

Compares the requested values with the predicted and the actual values for a current design.


**Inputs**

- **request** *(none)* -- Requested values.
- **predicted** *(none)* -- Predicted values (the generated sample).
- **real** *(none)* -- Actual values (the current design).

**Outputs**

- **comparison** -- Table with the comparison of the requested, predicted and actual values.

GenSelect
---------
.. image:: _images/icons/aixd_GenSelect.png
:align: left
:height: 24
:width: 24

Selects one of the designs generated from the trained model.


**Inputs**

- **predictions** *[List of (none)]* -- List of generated designs.
- **select** *(int)* -- Index of the selected design.

**Outputs**

- **sample_summary** -- Summary of the selected design.
- **generated_sample** -- Sample.
- **sample_summary** -- Selected sample.

ModelDimensions
---------------
Expand Down Expand Up @@ -376,6 +339,27 @@ Plots the distribution contours for each pair of variables from the data in the

- **img** -- Bitmap image if output_type is 'static', otherwise None.

PlotContoursRequest
-------------------
.. image:: _images/icons/aixd_PlotContoursRequest.png
:align: left
:height: 24
:width: 24

Plots the requested and predicted values against the distribution contours for each pair of the corresponding variables.


**Inputs**

- **request** *[List of (str)]* -- List of requested values, each formatted as a string with the following format: 'variable_name:value'.
- **output_type** *(str)* -- Plot type: 'static' creates a bitmap image, 'interactive' launches an interactive plot in a browser.
- **plot** *(bool)* -- Set to True to (re-)create the plot.
- **scale** *(float)* -- Resize factor for the static plot.

**Outputs**

- **img** -- Bitmap image if output_type is 'static', otherwise None.

PlotCorrelations
----------------
.. image:: _images/icons/aixd_PlotCorrelations.png
Expand Down
28 changes: 28 additions & 0 deletions src/aixd_grasshopper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ def get_dataobject_names_from_block():
return response


@app.route("/get_dataobject_types", methods=["POST"])
def get_dataobject_types():
data = request.data
data = json.loads(data)
session_id = data["session_id"]
sc = SessionController.create(session_id)

result = sc.get_dataobject_types()
response = json.dumps(result, cls=DataEncoder)
return response


@app.route("/plot_distrib_attributes", methods=["POST"])
def plot_distrib_attributes():
data = request.data
Expand Down Expand Up @@ -206,6 +218,22 @@ def plot_contours():
return response


@app.route("/plot_contours_request", methods=["POST"])
def plot_contours_request():
data = request.data
data = json.loads(data)
session_id = data["session_id"]
sc = SessionController.create(session_id)

output_type = data["output_type"]
requested_values = data["request"]
n_samples = data["n_samples"]

result = sc.plot_contours_request(request=requested_values, n_samples=n_samples, output_type=output_type)
response = json.dumps(result, cls=DataEncoder)
return response


@app.route("/design_parameters", methods=["GET"])
def get_design_parameters():
data = request.args
Expand Down
33 changes: 19 additions & 14 deletions src/aixd_grasshopper/components/aixd_DataObjectsNames/code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# this code has been inspired by a forum post by "chanley" (2018.11.02) https://discourse.mcneel.com/t/can-i-instantiate-specific-component-on-the-canvas-with-a-script-python/74204/8
# flake8: noqa

# this code has been inspired by a forum post by "chanley" (2018.11.02)
# https://discourse.mcneel.com/t/can-i-instantiate-specific-component-on-the-canvas-with-a-script-python/74204/8

import Grasshopper
import System.Drawing as sd
Expand All @@ -9,21 +12,22 @@
comp = ghenv.Component
ghdoc = comp.OnPingDocument()


def make_Panel(NickName, UserText, Pivot, Bounds):
try:
Panel = Grasshopper.Kernel.Special.GH_Panel()
Panel.NickName = NickName
Panel.UserText = UserText
Panel.Properties.Colour = sd.Color.White
#Panel.Properties.Font = sd.Font("Trebuchet MS", 10)
# Panel.Properties.Font = sd.Font("Trebuchet MS", 10)
Panel.Properties.Multiline = False
Panel.Properties.DrawIndices = False
Panel.Properties.DrawPaths = False
ghdoc.AddObject(Panel,False,ghdoc.ObjectCount+1)
ghdoc.AddObject(Panel, False, ghdoc.ObjectCount + 1)
Panel.Attributes.Pivot = Pivot
Panel.Attributes.Bounds = Bounds
except Exception, ex:
ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning,str(ex))
except Exception(ex):
ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, str(ex))


x = ghenv.Component.Attributes.DocObject.Attributes.Bounds.Right
Expand All @@ -36,20 +40,21 @@ def make_Panel(NickName, UserText, Pivot, Bounds):
errors = ""

if not datablock:
datablock = [ "design_parameters","performance_attributes","inputML","outputML"] #all datablock names
datablock = ["design_parameters", "performance_attributes", "inputML", "outputML"] # all datablock names

if get_names:

for i, datablock_nickname in enumerate(datablock):
panel_title = datablock_nickname
response = get_dataobject_names_from_block(session_id(),datablock_nickname)
text_items = response['names']
response = get_dataobject_names_from_block(session_id(), datablock_nickname)
text_items = response["names"]
if text_items:
text_str= "\n".join(text_items)
pt = sd.PointF(x + gap + i*gap, y + i*gap)
rect = sd.RectangleF(0,0,w,h)
text_str = "\n".join(text_items)
pt = sd.PointF(x + gap + i * gap, y + i * gap)
rect = sd.RectangleF(0, 0, w, h)
make_Panel(panel_title, text_str, pt, rect)
else:
errors+=response['msg']+"\n"
errors += response["msg"] + "\n"

if errors: ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning,str(errors))
if errors:
ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, str(errors))
114 changes: 11 additions & 103 deletions src/aixd_grasshopper/components/aixd_DatasetOneSample/code.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,25 @@
# flake8: noqa
import Grasshopper
from scriptcontext import sticky as st

from aixd_grasshopper.gh_ui import get_one_sample
from aixd_grasshopper.gh_ui_helper import component_id
from aixd_grasshopper.gh_ui_helper import instantiate_sample, sample_summary
from aixd_grasshopper.gh_ui_helper import session_id

cid = component_id(session_id(), ghenv.Component, "GetOneSample")


if not item:
item = -1

if get:
sample = get_one_sample(session_id(), item)


# TODO - clean up:


# -------------------------------------------------------------------------------
def find_component_by_nickname(ghdoc, component_nickname):
found = []
# all_objects = ghdoc.Objects
all_objects = ghenv.Component.OnPingDocument().Objects
for obj in all_objects:

if obj.Attributes.PathName == component_nickname:
# if obj.NickName == component_nickname:
found.append(obj)

if not found:
print("No ghcomponent found with a nickname {}.".format(component_nickname))
return
if len(found) > 1:
print("{len(found)} ghcomponents found with the nickname {} - will return None.".format(component_nickname))
return
return found[0]


def set_value(component, val):
component.Script_ClearPersistentData()
component.AddPersistentData(val)
component.ExpireSolution(True)


def set_values(component, vals):
"""
Data type of vals must match the type of the component.
See TYPES list.
"""
ghtype = TYPES[component.TypeName]

component.Script_ClearPersistentData()
if not isinstance(vals, list):
vals = [vals]
for v in vals:
component.PersistentData.Append(ghtype(v))
component.ExpireSolution(True)


TYPES = {
"Arc": Grasshopper.Kernel.Types.GH_Arc,
"Boolean": Grasshopper.Kernel.Types.GH_Boolean,
"Box": Grasshopper.Kernel.Types.GH_Box,
"Brep": Grasshopper.Kernel.Types.GH_Brep,
"Circle": Grasshopper.Kernel.Types.GH_Circle,
"ComplexNumber": Grasshopper.Kernel.Types.GH_ComplexNumber,
"Curve": Grasshopper.Kernel.Types.GH_Curve,
"Guid": Grasshopper.Kernel.Types.GH_Guid,
"Integer": Grasshopper.Kernel.Types.GH_Integer,
"Interval": Grasshopper.Kernel.Types.GH_Interval,
"Interval2D": Grasshopper.Kernel.Types.GH_Interval2D,
"Line": Grasshopper.Kernel.Types.GH_Line,
"Mesh": Grasshopper.Kernel.Types.GH_Mesh,
"Number": Grasshopper.Kernel.Types.GH_Number,
"Plane": Grasshopper.Kernel.Types.GH_Plane,
"Point": Grasshopper.Kernel.Types.GH_Point,
"Rectangle": Grasshopper.Kernel.Types.GH_Rectangle,
"String": Grasshopper.Kernel.Types.GH_String,
"SubD": Grasshopper.Kernel.Types.GH_SubD,
"Surface": Grasshopper.Kernel.Types.GH_Surface,
"Vector": Grasshopper.Kernel.Types.GH_Vector,
"Text": Grasshopper.Kernel.Types.GH_String,
}


# -------------------------------------------------------------------------------


if sample:

for dp_name, dp_vals in sample["design_parameters"].items():
# print dp_name, dp_vals
component_name = "GENERATED_{}".format(dp_name)
component = find_component_by_nickname(ghdoc, component_name)
print("{}: {}".format(component_name, dp_vals))

if not dp_vals:
print("empty values for {}".format(comp))
else:
set_values(component, dp_vals)

st[cid] = get_one_sample(session_id(), item)

# -------------------------------------------------------------------------------
if sample:
txt = ""
txt += "Design Parameters:\n\n"
for name, values in sample["design_parameters"].items():
txt += "{}: {}\n".format(name, values)
txt += "\n"
txt += "Performance Attributes:\n\n"
for name, values in sample["performance_attributes"].items():
txt += "{}: {}\n".format(name, values)
ghdoc = ghenv.Component.OnPingDocument()

sample = txt

trigger = False
if cid in st.keys():
sample = st[cid]
instantiate_sample(ghdoc, sample)

# sample = None
sample_summary = sample_summary(sample)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DatasetOneSample",
"nickname": "OneSample",
"nickname": "DatasetOneSample",
"category": "AIXD",
"subcategory": "2 Dataset",
"description": "Retrieves one sample from the dataset (at a given or random index) and instantiates it in the parametric model.",
Expand All @@ -25,7 +25,7 @@

"outputParameters": [
{
"name": "sample",
"name": "sample_summary",
"description": "Summary of the retrieved sample."
}
]
Expand Down
40 changes: 0 additions & 40 deletions src/aixd_grasshopper/components/aixd_GenSampleEval/code.py

This file was deleted.

Binary file not shown.
Loading
Loading