constrainthg 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ Al rights reserved. All code written and referenced in this package is the property of the authors listed below, and cannot be used without permission.
2
+
3
+ Authors:
4
+ - John Morris, jhmrrs@clemson.edu, https://orcid.org/0009-0005-6571-1959
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.1
2
+ Name: constrainthg
3
+ Version: 0.1.0
4
+ Summary: Methods for building and simulating constraint hypergraphs.
5
+ Author-email: John Morris <jhmrrs@clemson.edu>
6
+ License: All rights reserved
7
+ Project-URL: Homepage, https://github.com/jmorris335/ConstraintHg/wiki
8
+ Project-URL: Documentation, https://constrainthg.readthedocs.io/en/latest/
9
+ Project-URL: Repository, https://github.com/jmorris335/ConstraintHg
10
+ Project-URL: Bug Tracker, https://github.com/jmorris335/ConstraintHg/issues
11
+ Keywords: hypergraphs,systems engineering
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Programming Language :: Python
14
+ Requires-Python: >=3.1
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+
19
+ ![Static Badge](https://img.shields.io/badge/homepage-blue?link=https%3A%2F%2Fgithub.com%2Fjmorris335%2FConstraintHg%2Fwiki)
20
+ ![Read the Docs](https://img.shields.io/readthedocs/constrainthg?link=https%3A%2F%2Fconstrainthg.readthedocs.io%2Fen%2Flatest%2Findex.html) ![Static Badge](https://img.shields.io/badge/tests-passing-brightgreen) ![GitHub Release](https://img.shields.io/github/v/release/jmorris335/ConstraintHg?include_prereleases&display_name=tag) ![GitHub last commit](https://img.shields.io/github/last-commit/jmorris335/ConstraintHg)
21
+
22
+
23
+
24
+ # ConstraintHg
25
+ This repository enables usage of hypergraphs to define and execute system models. **It is not a rigorous data storage solution. Do not use this as a database.** Note that this repo is under active development (no official release yet), therefore changes may occur rapidly. Fork the repository before using it.
26
+
27
+ ## Install
28
+ ConstraintHg is listed on the Python Package Index. Just use `pip install constrainthg` to get started.
29
+
30
+ # Introduction
31
+ Hypergraphs are normal graphs but without the constraint that edges must only link between two nodes. Because of this expanded generality, hypergraphs can be used to model more complex relationships. For instance, the relationship `A + B = C` is a multinodal relationship between three nodes, A, B, and C. You can think of all three nodes being linked by a 2D hyperedge, so that to move along that hyperedge you need at least two of three nodes.
32
+
33
+ An constraint hypergraph is a hypergraph where the relationships are constraints that can be solved for by some execution engine, generally via API calls. These constraints reveal the behavior of the system. The goal is for the hypergraph to be platform agnostic, while API calls allow for edges to be processed on any available software.
34
+
35
+ Processing a series of nodes and edges (a "route") is what constitutes a simulation, so one of the uses of an constraint hypergraph is enabling high-level simulation ability from any possible entry point in a system model.
36
+
37
+ ## Getting started
38
+ *Note that this demo is found in [`demos/demo_basic.py`](https://github.com/jmorris335/ConstraintHg/blob/main/demos/demo_basic.py)*
39
+ Let's build a basic constraint hypergraph of the following equations:
40
+ - $A + B = C$
41
+ - $A = -D$
42
+ - $B = -E$
43
+ - $D + E = F$
44
+ - $F = -C$
45
+
46
+ First, import the classes.
47
+ ```[python]
48
+ from constrainthg.hypergraph import Hypergraph
49
+ import constrainthg.relations as R
50
+ ```
51
+
52
+ A hypergraph consists of edges that map between a set of nodes to a single node. We provide the mapping by defining a constraint function (many of which are already defined in the `relationships` module). The two relationships defined in the governing equations are addition and negation. Using the typical syntax, we refer to the functions defined in `relationships` with `R.<name>`, in this case `R.Rsum` and `R.Rnegate`. To make the hypergraph we'll need to compose the 5 edges (equations) given above.
53
+ ```[python]
54
+ hg = Hypergraph()
55
+ hg.addEdge(['A', 'B'], C, R.Rsum)
56
+ hg.addEdge('A', 'D', R.Rnegate)
57
+ hg.addEdge('B', 'E', R.Rnegate)
58
+ hg.addEdge(['D', 'E'], 'F', R.Rsum)
59
+ hg.addEdge('F', 'C', R.Rnegate)
60
+ ```
61
+
62
+ We can verify that the hypergraph was made correctly by tracing all possible paths for generating C using the `printPaths` function.
63
+ ```[python]
64
+ print(hg.printPaths('C'))
65
+ ```
66
+
67
+ This should give us the following output. Hyperedges are indicated with a `◯`, with the last source separated from other edges with a `●`.
68
+ ```
69
+ └──C, cost=1
70
+ ├◯─A, cost=0
71
+ ├●─B, cost=0
72
+ └──F, cost=3
73
+ ├◯─D, cost=1
74
+ │ └──A, cost=0
75
+ └●─E, cost=1
76
+ └──B, cost=0
77
+ ```
78
+
79
+ Compute the value of $C$ by picking a set of source nodes (inputs), such as $A$ and $B$ or $A$ and $E$. Set values for the inputs and the solver will automatically calulate an optimized route to simulate $C$.
80
+ ```[python]
81
+ print("**Inputs A and E**")
82
+ hg.solve('C', {'A':3, 'E':-7}, toPrint=True)
83
+ print("**Inputs A and B**")
84
+ hg.solve('C', {'A':3, 'B':7}, toPrint=True)
85
+ ```
86
+
87
+ The output of the above should be:
88
+ ```
89
+ **Inputs A and E**
90
+ └──C= 10, cost=3
91
+ └──F= -10, cost=2
92
+ ├──D= -3, cost=1
93
+ │ └──A= 3, cost=0
94
+ └──E= -7, cost=0
95
+
96
+ **Inputs A and B**
97
+ └──C= 10, cost=1
98
+ ├──A= 3, cost=0
99
+ └──B= 7, cost=0
100
+ ```
101
+
102
+ Check out the [demos](https://github.com/jmorris335/ConstraintHg/tree/main/demos) directory for more examples.
103
+
104
+ ## Licensing and Usage
105
+ Author: [John Morris](https://www.people.clemson.edu/jhmrrs/)
106
+ Organization: [PLM Center](https://github.com/Clemson-PLMC) at Clemson University
107
+ Contact: Reach out to my GitHub profile ([jmorris335](https://github.com/jmorris335))
108
+ Usage: An official release will *likely* be provided under the CC BY-NC-SA 4.0 license, but for now **all rights are reserved**. For usage, please reach out to the author directly.
@@ -0,0 +1,90 @@
1
+ ![Static Badge](https://img.shields.io/badge/homepage-blue?link=https%3A%2F%2Fgithub.com%2Fjmorris335%2FConstraintHg%2Fwiki)
2
+ ![Read the Docs](https://img.shields.io/readthedocs/constrainthg?link=https%3A%2F%2Fconstrainthg.readthedocs.io%2Fen%2Flatest%2Findex.html) ![Static Badge](https://img.shields.io/badge/tests-passing-brightgreen) ![GitHub Release](https://img.shields.io/github/v/release/jmorris335/ConstraintHg?include_prereleases&display_name=tag) ![GitHub last commit](https://img.shields.io/github/last-commit/jmorris335/ConstraintHg)
3
+
4
+
5
+
6
+ # ConstraintHg
7
+ This repository enables usage of hypergraphs to define and execute system models. **It is not a rigorous data storage solution. Do not use this as a database.** Note that this repo is under active development (no official release yet), therefore changes may occur rapidly. Fork the repository before using it.
8
+
9
+ ## Install
10
+ ConstraintHg is listed on the Python Package Index. Just use `pip install constrainthg` to get started.
11
+
12
+ # Introduction
13
+ Hypergraphs are normal graphs but without the constraint that edges must only link between two nodes. Because of this expanded generality, hypergraphs can be used to model more complex relationships. For instance, the relationship `A + B = C` is a multinodal relationship between three nodes, A, B, and C. You can think of all three nodes being linked by a 2D hyperedge, so that to move along that hyperedge you need at least two of three nodes.
14
+
15
+ An constraint hypergraph is a hypergraph where the relationships are constraints that can be solved for by some execution engine, generally via API calls. These constraints reveal the behavior of the system. The goal is for the hypergraph to be platform agnostic, while API calls allow for edges to be processed on any available software.
16
+
17
+ Processing a series of nodes and edges (a "route") is what constitutes a simulation, so one of the uses of an constraint hypergraph is enabling high-level simulation ability from any possible entry point in a system model.
18
+
19
+ ## Getting started
20
+ *Note that this demo is found in [`demos/demo_basic.py`](https://github.com/jmorris335/ConstraintHg/blob/main/demos/demo_basic.py)*
21
+ Let's build a basic constraint hypergraph of the following equations:
22
+ - $A + B = C$
23
+ - $A = -D$
24
+ - $B = -E$
25
+ - $D + E = F$
26
+ - $F = -C$
27
+
28
+ First, import the classes.
29
+ ```[python]
30
+ from constrainthg.hypergraph import Hypergraph
31
+ import constrainthg.relations as R
32
+ ```
33
+
34
+ A hypergraph consists of edges that map between a set of nodes to a single node. We provide the mapping by defining a constraint function (many of which are already defined in the `relationships` module). The two relationships defined in the governing equations are addition and negation. Using the typical syntax, we refer to the functions defined in `relationships` with `R.<name>`, in this case `R.Rsum` and `R.Rnegate`. To make the hypergraph we'll need to compose the 5 edges (equations) given above.
35
+ ```[python]
36
+ hg = Hypergraph()
37
+ hg.addEdge(['A', 'B'], C, R.Rsum)
38
+ hg.addEdge('A', 'D', R.Rnegate)
39
+ hg.addEdge('B', 'E', R.Rnegate)
40
+ hg.addEdge(['D', 'E'], 'F', R.Rsum)
41
+ hg.addEdge('F', 'C', R.Rnegate)
42
+ ```
43
+
44
+ We can verify that the hypergraph was made correctly by tracing all possible paths for generating C using the `printPaths` function.
45
+ ```[python]
46
+ print(hg.printPaths('C'))
47
+ ```
48
+
49
+ This should give us the following output. Hyperedges are indicated with a `◯`, with the last source separated from other edges with a `●`.
50
+ ```
51
+ └──C, cost=1
52
+ ├◯─A, cost=0
53
+ ├●─B, cost=0
54
+ └──F, cost=3
55
+ ├◯─D, cost=1
56
+ │ └──A, cost=0
57
+ └●─E, cost=1
58
+ └──B, cost=0
59
+ ```
60
+
61
+ Compute the value of $C$ by picking a set of source nodes (inputs), such as $A$ and $B$ or $A$ and $E$. Set values for the inputs and the solver will automatically calulate an optimized route to simulate $C$.
62
+ ```[python]
63
+ print("**Inputs A and E**")
64
+ hg.solve('C', {'A':3, 'E':-7}, toPrint=True)
65
+ print("**Inputs A and B**")
66
+ hg.solve('C', {'A':3, 'B':7}, toPrint=True)
67
+ ```
68
+
69
+ The output of the above should be:
70
+ ```
71
+ **Inputs A and E**
72
+ └──C= 10, cost=3
73
+ └──F= -10, cost=2
74
+ ├──D= -3, cost=1
75
+ │ └──A= 3, cost=0
76
+ └──E= -7, cost=0
77
+
78
+ **Inputs A and B**
79
+ └──C= 10, cost=1
80
+ ├──A= 3, cost=0
81
+ └──B= 7, cost=0
82
+ ```
83
+
84
+ Check out the [demos](https://github.com/jmorris335/ConstraintHg/tree/main/demos) directory for more examples.
85
+
86
+ ## Licensing and Usage
87
+ Author: [John Morris](https://www.people.clemson.edu/jhmrrs/)
88
+ Organization: [PLM Center](https://github.com/Clemson-PLMC) at Clemson University
89
+ Contact: Reach out to my GitHub profile ([jmorris335](https://github.com/jmorris335))
90
+ Usage: An official release will *likely* be provided under the CC BY-NC-SA 4.0 license, but for now **all rights are reserved**. For usage, please reach out to the author directly.
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "constrainthg"
7
+ version = "0.1.0"
8
+ dependencies = [
9
+ "numpy"
10
+ ]
11
+ requires-python = ">=3.1"
12
+ authors = [
13
+ {name = "John Morris", email = "jhmrrs@clemson.edu"},
14
+ ]
15
+ description = "Methods for building and simulating constraint hypergraphs."
16
+ readme = "README.md"
17
+ license = {text = "All rights reserved"}
18
+ keywords = ["hypergraphs", "systems engineering"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Programming Language :: Python"
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/jmorris335/ConstraintHg/wiki"
26
+ Documentation = "https://constrainthg.readthedocs.io/en/latest/"
27
+ Repository = "https://github.com/jmorris335/ConstraintHg"
28
+ "Bug Tracker" = "https://github.com/jmorris335/ConstraintHg/issues"
29
+
30
+ [project.scripts]
31
+ constrainthg-cli = "constrainthg:main_cli"
32
+
33
+ [tool.pytest.ini_options]
34
+ pythonpath = "src"
35
+ addopts = [
36
+ "--import-mode=importlib",
37
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ """Initialization file for ConstraintHg."""
2
+
3
+ import logging
4
+
5
+ from constrainthg.hypergraph import *
6
+ import constrainthg.relations as R
7
+
8
+ LOG_LEVEL = logging.INFO
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ fh = logging.FileHandler("constrainthg.log")
13
+ fh.setLevel(LOG_LEVEL)
14
+ logger.info('Package begin execution')
15
+
16
+ log_formatter = logging.Formatter(
17
+ fmt="[{asctime} | {levelname}]: {message}",
18
+ style="{",
19
+ datefmt="%Y-%m-%d %H:%M",
20
+ )
21
+ fh.setFormatter(log_formatter)
22
+ logger.addHandler(fh)
23
+
24
+ logger.setLevel(LOG_LEVEL)