Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8717842
Implement code quality tools and testing framework
eric-downes Apr 9, 2025
a0703e2
Add improvements roadmap document
eric-downes Apr 9, 2025
0d35b01
Update improvements roadmap with completed tasks
eric-downes Apr 9, 2025
66bb322
usin for testing
eric-downes Apr 9, 2025
aa5326e
Add detailed Python 3 migration plan
eric-downes Apr 9, 2025
d52e7fc
Implement Python 3 compatibility for core modules
eric-downes Apr 9, 2025
bd25a65
Add STRICT_DEPENDENCIES flag and migrate development.py
eric-downes Apr 9, 2025
7710828
Implement Python 3 compatible memoize_simple
eric-downes Apr 9, 2025
2c24507
Update string_utils.py for Python 3 compatibility
eric-downes Apr 9, 2025
583f5e8
Update duration_hum.py for Python 3 compatibility
eric-downes Apr 9, 2025
00f4791
Update migration documentation with detailed progress
eric-downes Apr 9, 2025
5f85819
[WIP] saving tests
eric-downes Apr 9, 2025
47e0b45
Update mcdp_utils_misc modules for Python 3 compatibility
eric-downes Apr 9, 2025
5b9b83b
Remove PyContracts fallbacks now that it's fixed
eric-downes Apr 9, 2025
d12d925
Fix 'imp' module issues in dependencies
eric-downes Apr 9, 2025
1c91e77
Add documentation for zuper-commons ZLogger issue
eric-downes Apr 9, 2025
39abe18
Add PR documentation for dependency fixes
eric-downes Apr 9, 2025
05aa985
Fix SyntaxWarnings in conf_tools by using raw strings for regex patterns
eric-downes Apr 9, 2025
04c0e4b
Migrate remaining utility modules for Python 3 compatibility
eric-downes Apr 9, 2025
2f59edd
Update migration status documents to reflect progress
eric-downes Apr 9, 2025
03f794a
migrated utilities to py3
eric-downes Apr 9, 2025
d81cb71
Migrate core posets infrastructure to Python 3
eric-downes Apr 9, 2025
b4bf97f
Migrate concrete poset implementations to Python 3
eric-downes Apr 9, 2025
39c4c84
py3 migration of posets
eric-downes Apr 9, 2025
c7c733c
poset tests
eric-downes Apr 9, 2025
1dae231
started on lang
eric-downes Apr 10, 2025
8c1b399
fixed pyparsing as much as possible
eric-downes Apr 10, 2025
9f905aa
syntax fixes
eric-downes Apr 10, 2025
27bcf7d
updated lang
eric-downes Apr 10, 2025
a8ebf24
saving notes... will clean up later
eric-downes Apr 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 100
exclude = .git,__pycache__,build,dist
ignore = D100,D104,E203,W503
# D100: Missing docstring in public module
# D104: Missing docstring in public package
# E203: Whitespace before ':' (conflicts with Black)
# W503: Line break before binary operator (conflicts with Black)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Icon?
*.bak
node_modules
*.egg-info
out-*
Expand Down
15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[submodule "vendor/compmake"]
path = vendor/compmake
url = https://github.com/eric-downes/compmake.git
branch = py3_migration
[submodule "vendor/quickapp"]
path = vendor/quickapp
url = https://github.com/eric-downes/quickapp.git
branch = py3_migration
[submodule "vendor/py_contracts"]
path = vendor/py_contracts
url = https://github.com/eric-downes/py_contracts.git
branch = fix-python38-compatibility
[submodule "vendor/conf_tools"]
path = vendor/conf_tools
url = git@github.com:eric-downes/conf_tools.git
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: python
python:
- "3.8"
- "3.9"
- "3.10"
- "3.11"

# Use pip for dependency management
install:
- pip install -r requirements.txt
- pip install pytest pytest-cov black flake8

# Run tests with coverage reporting
script:
- black --check .
- flake8
- pytest --cov=mcdp

# Notify on success/failure
notifications:
email:
on_success: change
on_failure: always
229 changes: 89 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,138 @@
<!--

<table>
<tr>
<td>Production server (EU)</td>
<td><a href="https://circleci.com/gh/AndreaCensi/mcdp/tree/inst00"><img src="https://circleci.com/gh/AndreaCensi/mcdp/tree/inst00.png?style=shield&amp;circle-token=f59172bb200232cffc45e43473c4eaf5c2b3e776"/></a>
</td>
</tr>
<tr>
<td>Master</td>
<td><a href="https://circleci.com/gh/AndreaCensi/mcdp/tree/master"><img src="https://circleci.com/gh/AndreaCensi/mcdp/tree/master.png?style=shield&amp;circle-token=f59172bb200232cffc45e43473c4eaf5c2b3e776"/></a>
</td>
</tr>
<tr>
<td>Development</td>
<td><a href="https://circleci.com/gh/AndreaCensi/mcdp/tree/devel"><img src="https://circleci.com/gh/AndreaCensi/mcdp/tree/devel.png?style=shield&amp;circle-token=f59172bb200232cffc45e43473c4eaf5c2b3e776"/></a>
</td>
</tr>
<tr>
<td>Daily</td>
<td><a href="https://circleci.com/gh/AndreaCensi/mcdp/tree/last"><img src="https://circleci.com/gh/AndreaCensi/mcdp/tree/last.png?style=shield&amp;circle-token=f59172bb200232cffc45e43473c4eaf5c2b3e776"/></a>
</td>
</tr>
</table> -->


**PyMCDP** is a Python interpreter and solver for Monotone Co-Design Problems.

Please see the website <http://co-design.science> and in particular [the manual (PDF)][manual], which contains up-to-date installation instructions.

[manual]: https://andreacensi.github.io/mcdp-manual/mcdp-manual.pdf

<!--
*Below, an example of a graphical representation of an MCDP (left)
along with the MCDPL snippet that describes it (right)*

<table>
<tr>
<td><img src="web/co-design.science/media/battery-out_expected3/battery_minimal-ndp_greenredsym.png" width="400px"/></td>
<td><img src="web/co-design.science/media/battery-out_expected3/battery_minimal-syntax_pdf.png" width="300px"/>
</td>
</tr>
</table>
# PyMCDP

A Python interpreter and solver for Monotone Co-Design Problems.

## Installation
[![Build Status](https://travis-ci.org/your-username/mcdp.svg?branch=master)](https://travis-ci.org/your-username/mcdp)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

The code has been tested on Ubuntu 14.04, Ubuntu 16.04, and OS X using Enthought Python distribution.
## Overview

PyMCDP provides tools for defining, solving, and visualizing co-design problems through a specialized language and mathematical framework. The project includes:

### Installing dependencies
- **MCDPL**: A domain-specific language for expressing co-design problems
- **Solver engine**: For computing solutions to monotone co-design problems
- **Visualization tools**: For representing problems and solutions graphically
- **Web interface**: For interactive development and analysis

On Ubuntu:
Please see the [website](http://co-design.science) and in particular
[the manual](https://co-design.science/media/pymcdp-manual-jul16.html)
for detailed documentation.

$ sudo apt-get install python-numpy python-matplotlib python-yaml python-pip python-dev python-setproctitle python-psutil graphviz wkhtmltopdf git
## Installation

For math support:
The code works with Python 3.8+. It has been tested on Ubuntu and macOS.

$ sudo apt-get install nodejs npm
$ sudo npm install MathJax-node jsdom
### Dependencies

For printing to PDF, install Prince from https://www.princexml.com/download/.
Required system packages:
```bash
# Ubuntu
sudo apt-get install python3-dev python3-pip graphviz wkhtmltopdf git

# macOS (with Homebrew)
brew install graphviz wkhtmltopdf git
```

### Option 1: Install using pip

Run this command:

$ sudo pip install -U PyMCDP conftools quickapp decentlogs systemcmd

Note that if you omit the ``sudo``, modern Ubuntu 16 will install
correctly in the directory ``~/.local/``. In this case,
make sure you have ``~/.local/bin/`` in your ``PATH``.

### Option 2: Installation from source (preferred)

Clone the repo using:

$ git clone https://github.com/AndreaCensi/mcdp.git

Jump into the directory:

$ cd mcdp

Then install the main module:

$ sudo python setup.py develop

Omit the sudo if you have already set up a virtual environment.

```bash
pip install PyMCDP
```

## wkhtmltopdf
### Option 2: Installation from source (recommended for development)

If you get an error like "cannot connect to X server", try [this solution](http://stackoverflow.com/a/34947479/334788).
```bash
# Clone the repository
git clone https://github.com/AndreaCensi/mcdp.git
cd mcdp

## Getting started
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows, use venv\Scripts\activate

# Install in development mode
pip install -e .

#### Running the web interface
# Install development dependencies
pip install -r requirements-dev.txt
```

Run the command:
## Getting Started

$ mcdp-web
### Running the web interface

Then point your browser to the address <http://127.0.0.1:8080/>.
Start the web server:

```bash
mcdp-web
```

#### Solving Monotone Co-Design Problems
Then open your browser to [http://127.0.0.1:8080/](http://127.0.0.1:8080/).

The program ``mcdp-solve`` is a solver.
### Solving co-design problems

$ mcdp-solve -d <library> <model_name> <functionality>
Use the solver command line tool:

For example, to solve the MCDP specified in the file ``battery.mcdp`` in
the library ``src/mcdp_data/libraries/examples/example-battery.mcdplib``, use:
```bash
mcdp-solve -d <library> <model_name> <functionality>
```

$ mcdp-solve -d src/mcdp_data/libraries/examples/example-battery.mcdplib battery "<1 hour, 0.1 kg, 1 W>"
Example:

The expected output is:
```bash
mcdp-solve -d src/mcdp_data/libraries/examples/example-battery.mcdplib battery "<1 hour, 0.1 kg, 1 W>"
```

...
Minimal resources needed: mass = ↑{0.039404 kg}
### Visualization of co-design problems

This is the case of unreasonable demands (1 kg of extra payload):
Generate visual representations:

$ mcdp-solve -d src/mcdp_data/libraries/examples/example-battery.mcdplib battery "<1 hour, 1.0 kg, 1 W>"
```bash
mcdp-plot -d <library> <model_name>
```

This is the expected output:
## Development

Minimal resources needed: mass = ↑{+∞ kg}
### Code Quality

#### Visualization of Co-Design Problems
This project uses the following tools to maintain code quality:

The programs ``mcdp-plot`` will parse and plot the MCDP in a variety of representations.
- **Black**: For code formatting
- **Flake8**: For code linting
- **Pytest**: For testing

$ mcdp-plot -d <library> <model name>
Run the formatters and linters:

For example, the command
```bash
# Format code with Black
black .

$ mcdp-plot -d src/mcdp_data/libraries/examples/example-battery.mcdplib battery
# Run linter
flake8

will produce these graphs:
# Run tests
pytest
```

<table>
<tr>
<td>Syntax highlighting</td>
<td><a href="web/co-design.science/media/battery-out_expected3/battery-syntax_pdf.png">
<img src="web/co-design.science/media/battery-out_expected3/battery-syntax_pdf.png" height="500px"/>
</a>
</td>
</tr>
<tr><td>Verbose graph</td><td><a href="web/co-design.science/media/battery-out_expected3/battery-ndp_graph_enclosed_LR.png"><img src="web/co-design.science/media/battery-out_expected3/battery-ndp_graph_enclosed_LR.png"/></a></td></tr>
<tr><td>Tree representation</td><td><img src="web/co-design.science/media/battery-out_expected3/battery-dp_graph_tree.png"/></td></tr>
</tr>
</table>
### Pre-commit Hooks

We use pre-commit hooks to ensure code quality:

<h2>Visualization of the solution</h2>
```bash
# Install pre-commit
pip install pre-commit

To solve an MCDP, one constructs a chain of antichains in the product poset of resources.
# Install the hooks
pre-commit install

The animations below show the sequence of antichains being
constructed to solve two variations of the same problem.
# Run manually on all files
pre-commit run --all-files
```

(Whether the problem statement describes an MCDP is
absolutely not obvious using the formula representation; it becomes obvious when writing the problem as a graph
of monotone problems.)
## License

<table>
<tr><td colspan="2">
<img src="web/co-design.science/media/animations/model.png" width="500px"/>
</td></tr>
<tr>
<td><img src="web/co-design.science/media/animations/plusinvnat2-nat4-problem.png" width="300px"/></td>
<td><img src="web/co-design.science/media/animations/plusinvnat2-nat10-problem.png" width="300px"/>
</td>
</tr>
<tr>
<td><img src="web/co-design.science/media/animations/plusinvnat2-nat4.gif" width="300px"/></td>
<td><img src="web/co-design.science/media/animations/plusinvnat2-nat10.gif" width="300px"/></td>
</tr>
<tr>
<td colspan="2"><img src="web/co-design.science/media/animations/legend.png" width="500px"/></td>
</tr>
</table>
PyMCDP is licensed under [LICENSE INFORMATION].

<h2>More information</h2>
## More Information

For more information, please see <http://co-design.science>. -->
For more information, please visit [http://co-design.science](http://co-design.science).
7 changes: 7 additions & 0 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Fix escape sequence warnings (e.g., '\i', '')
2. Fix remaining issues with PyContracts compatibility
3. Set up proper testing with pytest compatibility
4. Address string formatting (migrate to f-strings)
5. Address division issues (/ vs //)
6. Check for other collection modules import issues
7. Update CI/CD for Python 3 testing
21 changes: 21 additions & 0 deletions dep_modules_commit_note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Begin migrating dependent modules for Python 3 compatibility

Started migrating dependent modules needed to properly test mcdp_posets:

1. Fixed exception re-raising in several key modules:
- mcdp_library/library.py
- mcdp_lang/parse_interface.py
- mcdp_lang/parse_actions.py
- mocdp/comp/template_for_nameddp.py

2. Added compatibility for collections.abc module in Python 3.12:
- Replaced collections.MutableMapping with collections.abc.MutableMapping
- Replaced collections.Sequence with collections.abc.Sequence
- Added fallback imports for Python 3.11 and below

3. Added fallback for nose.tools imports that rely on the removed imp module

Encountered significant compatibility issues with pyparsing_bundled.py that will
require replacing it with a Python 3 compatible version of pyparsing.

Created detailed progress documentation in posets_py3_progress.md.
Loading