constrainthg

General system simulation using constraint hypergraphs

https://github.com/jmorris335/constrainthg

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.9%) to scientific vocabulary

Keywords

constraints-solver-algorithm mbse system-simulation
Last synced: 6 months ago · JSON representation ·

Repository

General system simulation using constraint hypergraphs

Basic Info
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • Open Issues: 17
  • Releases: 7
Topics
constraints-solver-algorithm mbse system-simulation
Created over 1 year ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md


DOI Read the Docs Static Badge GitHub Release GitHub last commit

ConstraintHg is a systems modeling kernel written in Python that enables general definition and universal simulation of any system. The kernel breaks a system down into the informational values (nodes) and functional relationships (hyperedges), providing robust simulation through pathfinding operations. This repository is under active development (no official release yet), and is therefore subject to change without warning. It is not a rigorous data storage solution. Do not use this as a database.

Uses

ConstraintHg enables the following functionalities: - Universal systems modeling: any model can be represented as a Constraint Hypergraph, meaning that models of different types and sources can be combined inside a single hypergraph. - Universal simulation: any simulation that could be conducted on a systems model can be discovered by ConstraintHg, or in other words, a program for calculating any piece of information (given a set of inputs) can be compiled for any system--given that such a program exists! - System interrogation: any system can be turned into a black box where information is autonomously returned by ConstraintHg--whether that information was recorded or simulated. This is especially useful for automatons trying to interface with a system. - Digital twin representation: modeling a real systsem with ConstraintHg is equivalent to creating a digital twin of that system, providing universal observation of the properties and biconnectiviy with the modeled system.

Links and More Information

Licensing and Usage

Author: John Morris
Contact: Reach out to my GitHub profile (jmorris335)
Usage: Released under the Apache 2.0 license. This permissive license allows you can use, modify, and distribute this source code as desired (official terms are in the LICENSE file). The main limitations are that you'll need to include a copy of this license as well as the NOTICE file, and you'll have to state your changes. We'd appreciate hearing if you used this for something helpful. Let us know by contacting us via our profiles!

Install

ConstraintHg is listed on the Python Package Index. To install, paste the following to your command terminal: pip install constrainthg

Introduction

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.

A 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.

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.

Getting started

Note that this demo is found in demos/demo_basic.py Let's build a basic constraint hypergraph of the following equations: - $A + B = C$ - $A = -D$ - $B = -E$ - $D + E = F$
- $F = -C$

First, import the classes. [python] from constrainthg.hypergraph import Hypergraph import constrainthg.relations as R

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. [python] hg = Hypergraph() hg.add_edge(['A', 'B'], 'C', R.Rsum) hg.add_edge('A', 'D', R.Rnegate) hg.add_edge('B', 'E', R.Rnegate) hg.add_edge(['D', 'E'], 'F', R.Rsum) hg.add_edge('F', 'C', R.Rnegate)

We can verify that the hypergraph was made correctly by tracing all possible paths for generating C using the printPaths function. [python] print(hg.print_paths('C'))

This should give us the following output. Hyperedges are indicated with a , with the last source separated from other edges with a . └──C, cost=1 ├◯─A, cost=0 ├●─B, cost=0 └──F, cost=3 ├◯─D, cost=1 │ └──A, cost=0 └●─E, cost=1 └──B, cost=0

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$. [python] print("**Inputs A and E**") hg.solve('C', {'A':3, 'E':-7}, to_print=True) print("**Inputs A and B**") hg.solve('C', {'A':3, 'B':7}, to_print=True)

The output of the above should be: ``` Inputs A and E └──C= 10, cost=3 └──F= -10, cost=2 ├──D= -3, cost=1 │ └──A= 3, cost=0 └──E= -7, cost=0

Inputs A and B └──C= 10, cost=1 ├──A= 3, cost=0 └──B= 7, cost=0 ```

Examples

Many examples are available in the demos directory. These, and other external examples include: - Pendulum: demonstrating model selection - Elevator: combining discrete-event simulation with a PID controller - Naval Microgrid: complex system featuring data querying and dynamic simulation and linear systems - Crankshaft: integrates CAD software (Onshape) with dynamic simulation

Owner

  • Name: John Morris
  • Login: jmorris335
  • Kind: user
  • Company: Product Lifecycle Management Center at Clemson University

Mechanical Engineering doctoral student in the United States

JOSS Publication

ConstraintHg: A Kernel for Systems Modeling and Simulation
Published
January 19, 2026
Volume 11, Issue 117, Page 9131
Authors
John Morris ORCID
Deptartment of Mechanical Engineering, Clemson University, Clemson, South Carolina, United States
Editor
Olexandr Konovalov ORCID
Tags
simulation modeling systems constraint hypergraphs

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: ConstraintHg
message: >-
  If you use this software, please cite it using the  
  metadata from this file, and let the authors know via
  their GitHub profiles.
type: software
authors:
  - given-names: John
    family-names: Morris
    email: jhmrrs@clemson.edu
    orcid: 'https://orcid.org/0009-0005-6571-1959'
    affiliation: PLM Center at Clemson University
identifiers:
  - type: doi
    value: 10.5281/zenodo.15278018
    description: DOI for repository (latest release)
repository-code: 'https://github.com/jmorris335/ConstraintHg'
url: 'https://constrainthg.readthedocs.io/en/latest/'
abstract: >-
  System modeling kernel enabling universal simulation of a
  system representation structured using a constraint
  hypergraph.
license: Apache-2.0
version: 0.2.2
date-released: '2025-04-23'

GitHub Events

Total
  • Create event: 8
  • Issues event: 14
  • Release event: 6
  • Watch event: 1
  • Delete event: 1
  • Issue comment event: 9
  • Public event: 1
  • Push event: 114
  • Pull request review event: 1
  • Pull request event: 6
  • Gollum event: 28
  • Fork event: 2
Last Year
  • Create event: 8
  • Issues event: 14
  • Release event: 6
  • Watch event: 1
  • Delete event: 1
  • Issue comment event: 9
  • Public event: 1
  • Push event: 114
  • Pull request review event: 1
  • Pull request event: 6
  • Gollum event: 28
  • Fork event: 2

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 32 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 8
  • Total maintainers: 1
pypi.org: constrainthg

Kernel for building and simulating constraint hypergraphs.

  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 32 Last month
Rankings
Dependent packages count: 10.1%
Average: 33.5%
Dependent repos count: 56.8%
Maintainers (1)
Last synced: 8 months ago

Dependencies

docs/requirements.txt pypi
  • furo ==2024.8.6
  • matplotlib ==3.9.2
  • numpy ==2.1.2
  • pytest ==8.3.3
pyproject.toml pypi
  • numpy *