Skip to content

Commit

Permalink
linitng and trying out single source version based on git
Browse files Browse the repository at this point in the history
  • Loading branch information
gbomarito committed Nov 4, 2024
1 parent 6a90bfc commit 5e40b01
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
2 changes: 0 additions & 2 deletions bingo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@
License for the specific language governing permissions and limitations under
the License.
"""

__version__ = "0.5.0"
41 changes: 30 additions & 11 deletions bingo/symbolic_regression/agraph/onnx_interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Wrapper around ONNX for deploying bingo equations
This module is a wrapper around the onnx package that allows for conversion of
bingo AGraph objects to the onnx standard.
"""

import numpy as np
from onnx import numpy_helper, TensorProto
from onnx.helper import (
Expand Down Expand Up @@ -49,18 +55,32 @@


def make_onnx_model(command_array, constants, name="bingo_equation"):
"""creates an onnx model from bingo agraph represntation
Parameters
----------
command_array : Nx3 array of int
acyclic graph stack
constants : tuple of numeric
numeric constants that are used in the equation
name : str, optional
name for onnx model, by default "bingo_equation"
Returns
-------
onnx Model
onnx represntation of the AGraph
"""

nodes = []
slice_inds = set()

X = make_tensor_value_info("X", TensorProto.FLOAT, [None, None])
Y = make_tensor_value_info("Y", TensorProto.FLOAT, [None])
C = numpy_helper.from_array(np.array(constants), name="C")
input_ = make_tensor_value_info("X", TensorProto.FLOAT, [None, None])
output = make_tensor_value_info("Y", TensorProto.FLOAT, [None])
initializer = numpy_helper.from_array(np.array(constants), name="C")
nodes.append(make_node("Constant", [], ["ax0"], value_ints=[0]))
nodes.append(make_node("Constant", [], ["ax1"], value_ints=[1]))

Y = make_tensor_value_info("Y", TensorProto.FLOAT, [None])

for i, (op, p1, p2) in enumerate(command_array):
output_name = f"O{i}" if i < len(command_array) - 1 else "Y"
if op == INTEGER:
Expand All @@ -85,15 +105,14 @@ def make_onnx_model(command_array, constants, name="bingo_equation"):
)
elif op in ABS_SAFETY:
nodes.append(make_node("Abs", [f"O{p1}"], [f"{output_name}aux"]))
inputs = (
inps = (
[f"{output_name}aux", f"O{p2}"]
if IS_ARITY_2_MAP[op]
else [f"{output_name}aux"]
)
nodes.append(make_node(ONNX_FUNCTIONS[op], inputs, [output_name]))
nodes.append(make_node(ONNX_FUNCTIONS[op], inps, [output_name]))
else:
inputs = [f"O{p1}", f"O{p2}"] if IS_ARITY_2_MAP[op] else [f"O{p1}"]
nodes.append(make_node(ONNX_FUNCTIONS[op], inputs, [output_name]))
inps = [f"O{p1}", f"O{p2}"] if IS_ARITY_2_MAP[op] else [f"O{p1}"]
nodes.append(make_node(ONNX_FUNCTIONS[op], inps, [output_name]))

graph = make_graph(nodes, name, [X], [Y], [C]) # inputs # outputs # initializers
return make_model(graph)
return make_model(make_graph(nodes, name, [input_], [output], [initializer]))
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ requires = [
"ninja",
"cmake>=3.12",
"pybind11[global]",
"setuptools-scm>=8",
]
build-backend = "setuptools.build_meta"

[project]
name = "bingo"
dynamic = ["version"]
dependencies = [
"mpi4py>=2.0.0,<4.0",
"numpy",
Expand All @@ -32,4 +35,6 @@ TESTS = [
]

[tool.cibuildwheel]
skip = "pp*"
skip = "pp*"

[tool.setuptools_scm]
12 changes: 0 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
}


def get_property(prop, project):
result = re.search(
r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop),
open(project + "/__init__.py").read(),
)
return result.group(1)


__version__ = get_property("__version__", "bingo")


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
Expand Down Expand Up @@ -140,7 +129,6 @@ def build_extension(self, ext: CMakeExtension) -> None:

setup(
name="bingo-nasa",
version=__version__,
author="Geoffrey Bomarito",
author_email="[email protected]",
description="A package for genetic optimization and symbolic regression",
Expand Down

0 comments on commit 5e40b01

Please sign in to comment.