Skip to content

Commit

Permalink
Milestone 5 Pull Request (#337)
Browse files Browse the repository at this point in the history
* In progress changes for bucky v2 handling

* Updating Gromet primitive map with concatenate and other sequence related operators

* Adding cast and slice primitives

* Updating get/set primitive ops

* Adding a giant set of changes to support Milestone 5 release.

* Temporarily disabling cast_to_ann_cast_grfn_2_2 tests due to default_value addition to CAST/AnnCAST

Co-authored-by: Vincent Raymond <[email protected]>
  • Loading branch information
titomeister and Vincent Raymond authored Jan 4, 2023
1 parent d7f3ac6 commit f1f3c15
Show file tree
Hide file tree
Showing 20 changed files with 761 additions and 1,137 deletions.
2 changes: 1 addition & 1 deletion automates/gromet/execution_engine/primitive_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ def is_primitive(op: str, language: str):
cast_primitive_dict[class_obj.source_language_name["CAST"]] = class_obj

primitive_map = {"Python": python_primitive_dict, "GCC": gcc_primitive_dict, "CAST": cast_primitive_dict}
print(primitive_map["CAST"])


1 change: 1 addition & 0 deletions automates/gromet/execution_engine/types/defined_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Field:
name: str
type: str
variatic: bool = False
default_val: Any = None

@dataclass
class RecordField:
Expand Down
16 changes: 15 additions & 1 deletion automates/gromet/execution_engine/types/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@ class new_Map(object): # TODO: Should we have inputs for this?
documentation = ""

def exec() -> Dict:
return {}
return {}

class Map_get(object):
source_language_name = {"CAST":"map_get"}
inputs = [Field("map_input", "Map"), Field("index", "Hashable")]
outputs = [Field("element", "Any")]
shorthand = "map_get"
documentation = ""

class Map_set(object):
source_language_name = {"CAST":"map_set"}
inputs = [Field("map_set", "Map"), Field("index", "Hashable"), Field("element", "Any")]
outputs = [Field("map_output", "Map")]
shorthand = "map_set"
documentation = ""
31 changes: 25 additions & 6 deletions automates/gromet/execution_engine/types/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,43 @@ def exec(operand1: Any, operand2: Any) -> bool:

class IsInstance(object):
source_language_name = {"Python": "isinstance"}
inputs = [Field("operand", "Any"), Field("type", "Type")] # TODO: Get confirmation on adding Type field
inputs = [Field("operand", "Any"), Field("type_name", "String")] # TODO: Get confirmation on adding Type field
outputs = [Field("result", "Boolean")]
shorthand = "type"
documentation = ""

def exec(operand: Any, type: type) -> bool: # TODO: Fix name of right argument
def exec(operand: Any, type_name: str) -> bool: # TODO: Fix name of right argument
return isinstance(operand, type)

class Type(object):
source_language_name = {"Python": "type"}
inputs = [Field("operand", "Any")]
outputs = [Field("result", "Type")]
outputs = [Field("result", "String")]
shorthand = "type"
documentation = ""

def exec(operand: Any) ->type:
return type(operand)
def exec(operand: Any) -> str:
return str(type(operand))

class Cast(object):
source_language_name = { "CAST": "cast"}
inputs = [Field("operand", "Any")]
outputs = [Field("type_name", "String")]
shorthand = "cast"
documentation = ""

class Slice(object):
source_language_name = { "CAST": "slice"}
inputs = [Field("lower", "Integer"), Field("upper", "Integer"), Field("step", "Integer")]
outputs = [Field("output_slice", "Slice")]
shorthand = "slice"
documentation = ""

class ExtSlice(object):
source_language_name = { "CAST": "ext_slice"}
inputs = [Field("dims", "List")]
outputs = [Field("output_slice", "ExtSlice")]
shorthand = "ext_slice"

class Print: #TODO: How should print work? Will likely not be a CASTGeneric function
source_language_name = {"CAST":"print"}
Expand All @@ -68,7 +87,7 @@ def exec(input: Any) -> None:

class Range:
source_language_name = {"CAST":"range"}
inputs = [Field("input", "Integer")] #TODO: What is the input to range?
inputs = [Field("stop", "integer"), Field("start", "integer", default_val=0), Field("step", "integer", default_val=1)] #TODO: What is the input to range?
outputs = [Field("range_output", "Range")]
shorthand = "range"
documentation = ""
Expand Down
13 changes: 13 additions & 0 deletions automates/gromet/execution_engine/types/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ def exec(record_input: Record, field_name: str, value_type: type) -> Record:
return record_input.fields.append(RecordField(field_name, value_type, None)) # #TODO: Do we need to set a default value?


class Record_get(object):
source_language_name = {"CAST":"record_get"}
inputs = [Field("record_input", "Record"), Field("index", "String")]
outputs = [Field("field_output", "Field")]
shorthand = "record_get"
documentation = ""

class Record_set(object):
source_language_name = {"CAST":"record_set"}
inputs = [Field("record_input", "Record"), Field("index", "String"), Field("element", "Any")]
outputs = [Field("record_output", "Record")]
shorthand = "record_set"
documentation = ""
108 changes: 55 additions & 53 deletions automates/gromet/execution_engine/types/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,106 +4,108 @@

from automates.gromet.execution_engine.types.defined_types import Field, Sequence

class Sequence_concatenate(object): #TODO: Check implementation of *args
source_language_name = {}
#TODO: Check the correctness for numpy arrays - How do n>1d arrays work in this case

class Sequence_get(object):
source_language_name = {"CAST":"sequence_get"}
inputs = [Field("sequence_input", "Sequence"), Field("index", "DimensionalIndex")]
outputs = [Field("sequence_output", "Sequence")]
shorthand = "sequence_get"
documentation = ""

class Sequence_set(object):
source_language_name = {"CAST":"sequence_set"}
inputs = [Field("sequence_input", "Sequence"), Field("index", "DimensionalIndex"), Field("element", "Any")]
outputs = [Field("sequence_output", "Sequence")]
shorthand = "sequence_set"
documentation = ""

class Sequence_concatenate(object):
source_language_name = {"CAST":"concatenate"}
inputs = [Field("sequence_inputs", "Sequence", True)]
outputs = [Field("sequence_output", "Sequence")]
shorthand = ""
documentation = ""

def exec(*sequence_inputs : Sequence) -> Sequence:
if isinstance(list(sequence_inputs)[0], numpy.ndarray):
return Sequence_concatenate.Array_concatenate()
elif isinstance(list(sequence_inputs)[0], List):
return Sequence_concatenate.List_concatenate()
elif isinstance(list(sequence_inputs)[0], Tuple):
return Sequence_concatenate.Tuple_concatenate()
# TODO: How do we handle type checking, whose responsibility should it be?
assert type(sequence_inputs[0] != range) # Range type doesn't support concatenation
assert all(isinstance(sequence, type(sequence_inputs[0])) for sequence in sequence_inputs) # Cannot concatenate sequences of different types

if isinstance(sequence_inputs[0], numpy.ndarray):
Sequence_concatenate.Array_concatenate(sequence_inputs)
else:
# Range does not support concatenate, so this is a placeholde
pass
return type(sequence_inputs[0])(itertools.chain.from_iterable(sequence_inputs))

def List_concatenate(*list_inputs: List) -> List:
return sum(list_inputs, [])
def Array_concatenate(*array_inputs: numpy.ndarray) -> numpy.ndarray:
def Array_concatenate(array_inputs: Tuple[numpy.ndarray, ...]) -> numpy.ndarray:
return numpy.concatenate(array_inputs)
def Tuple_concatenate(*tuple_inputs: Tuple) -> Tuple:
return sum(tuple_inputs, ())



class Sequence_replicate(object):
source_language_name = {}
source_language_name = {"CAST":"replicate"}
inputs = [Field("sequence_input", "Sequence"), Field("count", "Integer") ]
outputs = [Field("sequence_output", "Sequence")]
shorthand = ""
documentation = ""

def exec(sequence_input: Sequence, count: int) -> Sequence:
if isinstance(sequence_input, List):
return Sequence_replicate.List_replicate(sequence_input, count)
elif isinstance(sequence_input, numpy.ndarray):
assert type(sequence_input != range)
if isinstance(sequence_input, numpy.ndarray):
return Sequence_replicate.Array_replicate(sequence_input, count)
else:
return sequence_input*count

def Array_replicate(array_input: numpy.ndarray, count: int) -> numpy.ndarray:
return numpy.tile(array_input, count)



class List_replicate(object):
source_language_name = {}
inputs = [Field("list_input", "List"), Field("count", "Integer") ]
outputs = [Field("list_output", "List")]
shorthand = ""
documentation = ""

def exec(list_input: List, count: int) -> List:
return [list_input]*count

class List_length(object):
source_language_name = {}
inputs = [Field("list_input", "List")]
class Sequence_length(object):
source_language_name = {"CAST": "length"}
inputs = [Field("sequence_input", "Sequence")]
outputs = [Field("length", "Integer")]
shorthand = ""
documentation = ""

def exec(list_input: List) -> int:
return len(list_input)
def exec(sequence_input: Sequence) -> int:
return len(sequence_input)

class List_min(object):
source_language_name = {}
inputs = [Field("list_input", "List")]
class Sequence_min(object):
source_language_name = {"CAST": "min"}
inputs = [Field("sequence_input", "Sequence")]
outputs = [Field("minimum", "Any")]
shorthand = ""
documentation = ""

def exec(list_input: List) -> Any:
return min(list_input)
def exec(sequence_input: Sequence) -> Any:
return min(list(sequence_input))

class List_max(object):
source_language_name = {}
inputs = [Field("list_input", "List")]
class Sequence_max(object):
source_language_name = {"CAST": "max"}
inputs = [Field("sequence_input", "Sequence")]
outputs = [Field("maximum", "Any")]
shorthand = ""
documentation = ""

def exec(list_input: List) -> Any:
return max(list_input)
def exec(sequence_input: Sequence) -> Any:
return max(list(sequence_input))

class List_count(object):
source_language_name = {}
inputs = [Field("list_input", "List"), Field("element", "Any")]
class Sequence_count(object):
source_language_name = {"CAST": "count"}
inputs = [Field("sequence_input", "Sequence"), Field("element", "Any")]
outputs = [Field("count", "Integer")]
shorthand = ""
documentation = ""

def exec(list_input: List, element: Any) -> Any:
return list_input.count(element)
def exec(sequence_input: Sequence, element: Any) -> Any:
return list(sequence_input).count(element)

class List_index(object):
source_language_name = {}
class Sequence_index(object):
source_language_name = {"CAST": "index"}
inputs = [Field("list_input", "List"), Field("element", "Any")]
outputs = [Field("index", "Integer")]
shorthand = ""
documentation = ""

def exec(list_input: List, element: Any) -> Any:
return list_input.index(element)
return list(list_input).index(element)
Loading

0 comments on commit f1f3c15

Please sign in to comment.