Skip to main content

pyutils27 (cgshop2027-pyutils)

Utilities for working with CG:SHOP 2027 instances & solutions. This is a pure Python package containing a parser/verifier for our instance format, solution format and a verifier for solutions.


Installation

pip install cgshop2027-pyutils

The current state of main, ahead of the latest release:

pip install git+https://github.com/CG-SHOP/pyutils27

From a local clone (editable, for development):

git clone https://github.com/CG-SHOP/pyutils27
cd pyutils27
pip install -e ".[dev]"

Layout

src/cgshop2027_pyutils/
├── schemas/            # Pydantic models for instances & solutions
├── io/                 # reading instances & solutions from paths or file objects
├── zip/                # safe reading/writing of instance & solution archives
├── instance_database/  # query instances from a folder or a zip
├── grid.py             # cell-set algebra on the integer grid
├── verify.py           # checking a solution against its instance
└── visualize.py        # matplotlib plots and animations
tests/                  # pytest test suite

Usage

Verifying a solution against its instance:

from cgshop2027_pyutils.io import read_instance, read_solution
from cgshop2027_pyutils.verify import check_for_errors

errors = check_for_errors(
    read_instance("demo.instance.json"),
    read_solution("demo.solution.json"),
)

check_for_errors returns a list of human-readable messages; an empty list means the solution is feasible. When checking many solutions for the same instance, use SolutionValidator(instance) directly so that the instance-derived precomputation is only paid once.

A solution consists of exactly number_of_cutters tours, one per cutter:

solution = CGSHOP2027Solution(
    instance_uid="demo",
    tours=[{"x": [0, 3, 3, 0], "y": [0, 0, 1, 1]}, {"x": [7], "y": [7]}],
)

Each tour lists the points the cutter's center passes through and is closed implicitly, so the cutter travels from the last point back to the first one. Consecutive points must be axis-parallel; a point may be visited again later, but not immediately again. A tour of a single point is a cutter that stays where it is. Cutters do not interfere with each other and may leave the region; all that is required is that together they sweep the whole region.

The objective is solution.max_tour_length, the length of the longest tour, and it is to be minimized.

Bundling instances or solutions into an archive:

from cgshop2027_pyutils.zip import ZipWriter

with ZipWriter("solutions.zip") as writer:
    for solution in solutions:
        writer.add_solution(solution)

Reading a submitted archive, with size, CRC and path-traversal checks:

from cgshop2027_pyutils.zip import BadSolutionFile, ZipSolutionIterator, ZipReaderError

try:
    for solution in ZipSolutionIterator("solutions.zip"):
        print(solution.instance_uid)
except (ZipReaderError, BadSolutionFile) as e:
    print(f"Rejected: {e}")

example_zip.ipynb walks the whole submission path end to end: reading the instances, checking solutions against them, packing an archive, and what a rejection looks like. It runs on the two archives next to it: example_instances.zip, a copy of the published example instances, and example_solutions.zip, one feasible solution for each of them to check against and to beat.

Looking instances up by name, from either a folder or a zip:

from cgshop2027_pyutils.instance_database import InstanceDatabase

db = InstanceDatabase("instances.zip")
instance = db["demo"]
for instance in db:
    ...

Plotting an instance, a solution, or an animation of the cutters at work:

from cgshop2027_pyutils.visualize import (
    create_instance_plot,
    create_solution_animation,
    create_solution_plot,
)

create_instance_plot(instance).savefig("instance.png")
create_solution_plot(instance, solution).savefig("solution.png")

animation = create_solution_animation(instance, solution)
animation.save("solution.gif", writer="pillow")

The solution plot shades the swept area, marks any cells left uncovered in red and draws one tour per cutter. The animation strides through the tours to fit max_frames (300 by default), filling in coverage as the cutters move; pass step to control the stride yourself.

All three take bare=True, which drops the axes, the grid and every title and trims the figure to the drawing, for a picture meant for a paper or a slide rather than for debugging:

create_solution_plot(instance, solution, bare=True).savefig("solution.pdf")

Instance files must be named NAME.instance.json. A lookup key may be the bare name, the file name, or a path to it: db["demo"], db["demo.instance.json"] and db["batch1/demo.instance.json"] all resolve to the same instance. Note that every .json file in the folder or archive is treated as an instance, so keep solutions in a separate location.


Development

Set up the tooling (linting & formatting run through pre-commit):

pip install -e ".[dev]"
pre-commit install

Run the checks manually:

ruff check .
ruff format .
pytest

Linting, formatting and import sorting are all handled by ruff; its configuration lives in pyproject.toml.


Contributing

Issues & PRs welcome. Please:

  1. Add/adjust unit tests for new behavior
  2. Keep the public API documented here
  3. Run the test suite before submitting

Changelog

  • 0.1.0 (2026-08-25): First release. Instance and solution schemas, the solution verifier, archive reading and writing, the instance database, and plotting and animation.

License

MIT, see LICENSE.

Metadata

Release files for cgshop2027-pyutils 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cgshop2027-pyutils 0.1.0
File Size Uploaded
cgshop2027_pyutils-0.1.0.tar.gz 44.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cgshop2027-pyutils 0.1.0
File Interpreter ABI Platform
cgshop2027_pyutils-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.5 kB

Release files / cgshop2027_pyutils-0.1.0.tar.gz

Download URL cgshop2027_pyutils-0.1.0.tar.gz
Size 44.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d1a6f47c598b79e0e2ca4744a03b04e9f75f776b87cc8a92c2e047bf494c80e9
BLAKE2b-256 checksum
How to use checksums
613e3e3bb00ed2b08f17e0f3cf213abf6f164861db1cffd6e066fdc0f0413551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / cgshop2027_pyutils-0.1.0-py3-none-any.whl

Download URL cgshop2027_pyutils-0.1.0-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3e285352273801eab8a595cbcaafd5304c56a753a2c6aa98967b7428c3752a7
BLAKE2b-256 checksum
How to use checksums
0427e028b5f357e78d4a416900ce8a712364c68d3f29e8deeded8f6017e2fc50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page