Skip to content

Add nested modello feature #20

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Empty file added examples/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions examples/nested_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Example showing nested models.

>>> box = Box("B", base={"a": 3, "b": 4}, height=12)
>>> box.base.c
5
>>> box.diagonal
13
"""
from modello import InstanceDummy, Modello
from examples.geometry import RightAngleTriangle
from sympy import sqrt


class Box(Modello):
"""Simple box using a RightAngleTriangle as the base."""

base = RightAngleTriangle
height = InstanceDummy("height", positive=True)
diagonal = sqrt(base.c ** 2 + height ** 2)

23 changes: 23 additions & 0 deletions examples/nested_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Example demonstrating nested models with a Line composed of Points.

>>> line = Line("L", start={"x": 0, "y": 0}, end={"x": 3, "y": 4})
>>> line.length
5
"""
from modello import InstanceDummy, Modello
from sympy import sqrt


class Point(Modello):
"""Simple 2D point."""

x = InstanceDummy("x", real=True)
y = InstanceDummy("y", real=True)


class Line(Modello):
"""Line consisting of two points."""

start = Point
end = Point
length = sqrt((end.x - start.x) ** 2 + (end.y - start.y) ** 2)
18 changes: 18 additions & 0 deletions examples/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ class DoubleDataEntryFlow(ScalableFlow):
unit_output = Rational(8 * 260, 24 * 365) / entry_time / 2


class EntrySystem(Modello):
"""Simple system demonstrating nesting of flows.

>>> sys = EntrySystem(
... "SYS",
... flow={"input": 20, "entry_time": 5, "unit_cost": Rational(1, 10), "scale": 2},
... overhead=1,
... )
>>> sys.total_cost
6/5
"""

flow = SingleDataEntryFlow
overhead = InstanceDummy("overhead", positive=True, rational=True)
total_cost = flow.cost + overhead



def test_simple_system():
"""The wheels on the bus go round and round."""
channel_input_rates = {"foo": 12, "bar": 3}
Expand Down
Loading
Loading