Skip to main content

Support for interpreting knitout files used for controlling automatic V-Bed Knitting machines.

Project description

knitout-interpreter

PyPI - Version PyPI - Python Version License: MIT Code style: MyPy Pre-commit

A comprehensive Python library for interpreting and executing knitout files used to control automatic V-Bed knitting machines. This library provides full support for the Knitout specification created by McCann et al., enabling programmatic knitting pattern analysis, validation, and execution simulation.

๐Ÿ“‘ Table of Contents

๐Ÿงถ Overview

The knitout-interpreter bridges the gap between high-level knitting pattern descriptions and machine-level execution. It provides tools for:

  • Parsing knitout files into structured Python objects
  • Validating knitting instructions against common errors
  • Simulating execution on virtual knitting machines
  • Analyzing patterns for timing, width requirements, and complexity
  • Reorganizing instructions for optimal machine execution

๐Ÿš€ Key Features

Core Functionality

  • โœ… Full compliance with Knitout specification v2
  • โœ… Support for all needle operations (knit, tuck, split, drop, xfer, miss, kick)
  • โœ… Carrier management (in, out, inhook, outhook, releasehook)
  • โœ… Racking and positioning controls
  • โœ… Header processing (machine, gauge, yarn, carriers, position)

Advanced Analysis

  • ๐Ÿ“Š Execution Time Analysis: Measure knitting time in carriage passes
  • ๐Ÿ“ Width Calculation: Determine required needle bed width
  • ๐Ÿ” Error Detection: Identify common knitting errors before execution
  • ๐Ÿ“ˆ Knit Graph Generation: Create structured representations of the final fabric

Virtual Machine Integration

  • ๐Ÿ–ฅ๏ธ Built on the virtual-knitting-machine library
  • ๐Ÿง  Maintains complete machine state during execution
  • ๐Ÿ“‹ Tracks loop creation, movement, and removal from the machine bed
  • โš ๏ธ Provides detailed warnings for potential issues

๐Ÿ“ฆ Installation

From PyPI (Recommended)

pip install knitout-interpreter

From Source

git clone https://github.com/mhofmann-Khoury/knitout_interpreter.git
cd knitout_interpreter
pip install -e .

Development Installation

git clone https://github.com/mhofmann-Khoury/knitout_interpreter.git
cd knitout_interpreter
pip install -e ".[dev]"
pre-commit install

From Test-PyPi

If you wish to install an unstable release from test-PyPi, note that this will have dependencies on PyPi repository. Use the following command to gather those dependencies during install.

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ knitout-interpreter

๐Ÿƒโ€โ™‚๏ธ Quick Start

Basic Usage

"""Example Run of Knitout processed into instruction, final machine state, and resulting knit_graph"""
from knitout_interpreter.run_knitout import run_knitout

# Parse and execute a knitout file
instructions, machine, knit_graph = run_knitout("pattern.k")

print(f"Executed {len(instructions)} instructions")

Advanced Analysis with Knitout Executer

""" Example of parsing knitout lines from the knitout parser and organizing the executed instructions with the Knitout Executer."""
from knitout_interpreter.knitout_execution import Knitout_Executer
from knitout_interpreter.knitout_language.Knitout_Parser import parse_knitout
from virtual_knitting_machine.Knitting_Machine import Knitting_Machine

# Parse knitout file
instructions = parse_knitout("complex_pattern.k", pattern_is_file=True)

# Execute with analysis
executer = Knitout_Executer(instructions, Knitting_Machine())

# Get execution metrics
print(f"Execution time: {executer.execution_time} carriage passes")
print(f"Width required: {executer.left_most_position} to {executer.right_most_position}")

# Save reorganized instructions
executer.write_executed_instructions("executed_pattern.k")

๐Ÿ“š Core Components

Knitout Executer

The main analysis class that provides comprehensive execution simulation:

"""Example of loading a fully specified Knitout Executer"""
from knitout_interpreter.knitout_execution import Knitout_Executer
from knitout_interpreter.knitout_language.Knitout_Parser import parse_knitout
from virtual_knitting_machine.Knitting_Machine import Knitting_Machine

# Parse knitout file
parsed_instructions = parse_knitout("example.k", pattern_is_file=True)

executer = Knitout_Executer(
    instructions=parsed_instructions,
    knitting_machine=Knitting_Machine(),
    accepted_error_types=[],  # Optional: Knitting Machine Errors to ignore
    knitout_version=2
)

Key Properties:

  • execution_time: Number of carriage passes that will be executed
  • left_most_position / right_most_position: The range of needle positions in the executed file.
  • carriage_passes: List of carriage passes in the order they are executed.
  • resulting_knit_graph: Final fabric structure

Instruction Types

The library supports all knitout operations as Python classes:

Needle Operations

  • Knit_Instruction: Create new loops, stitch through the old one.
  • Tuck_Instruction: Create new loops, keeping old ones.
  • Split_Instruction: Creates a loop on first specified needle while moving existing loops to the second specified needle.
  • Drop_Instruction: Remove loops from needles
  • Xfer_Instruction: Transfer loops between needles
  • Miss_Instruction: Position carriers without forming loops
  • Kick_Instruction: Specialized miss for kickbacks

Carrier Operations

  • In_Instruction / Out_Instruction: Move carriers in/out of knitting area
  • Inhook_Instruction / Outhook_Instruction: Move carriers in/out of knitting area using yarn-inserting hook.
  • Releasehook_Instruction: Release carriers on the yarn-inserting hook.

Machine Control

  • Rack_Instruction: Set bed alignment and all-needle mode.
  • Pause_Instruction: Pause machine execution.

Header Declarations

  • Machine_Header_Line: Specify machine type.
  • Gauge_Header_Line: Set machine gauge.
  • Yarn_Header_Line: Define yarn properties.
  • Carriers_Header_Line: Configure available carriers.
  • Position_Header_Line: Set knitting position.

Carriage Pass Organization

The library automatically organizes instructions into carriage passes:

"""Example of what information can be gathered from carriage passes in the knitout execution."""
from knitout_interpreter.knitout_execution import Knitout_Executer
from knitout_interpreter.knitout_language.Knitout_Parser import parse_knitout
from virtual_knitting_machine.Knitting_Machine import Knitting_Machine

# Parse knitout file
parsed_instructions = parse_knitout("example.k", pattern_is_file=True)

executer = Knitout_Executer(
    instructions=parsed_instructions,
    knitting_machine=Knitting_Machine(),
    accepted_error_types=[],  # Optional: Knitting Machine Errors to ignore
    knitout_version=2
)

for carriage_pass in executer.carriage_passes:
    print(f"Pass direction: {carriage_pass.direction}")
    print(f"Instructions: {len(carriage_pass)}")
    print(f"Needle range: {carriage_pass.carriage_pass_range()}")
    print(f"Carriers used: {carriage_pass.carrier_set}")

๐Ÿ“– Examples

Example 1: Basic Stockinette

"""Example of loading basic stockinette knitout from a string."""
from knitout_interpreter.knitout_language.Knitout_Parser import parse_knitout

knitout_code = """
;!knitout-2
;;Machine: SWG091N2
;;Gauge: 15
;;Yarn-5: 50-50 Rust
;;Carriers: 1 2 3 4 5 6 7 8 9 10
;;Position: Right
inhook 1;
tuck + f1 1;
tuck + f2 1;
tuck + f3 1;
tuck + f4 1;
knit - f4 1
knit - f3 1
knit - f2 1
knit - f1 1
knit + f1 1;
knit + f2 1;
knit + f3 1;
knit + f4 1;
knit - f4 1
knit - f3 1
knit - f2 1
knit - f1 1
releasehook 1;
outhook 1;
"""

instructions = parse_knitout(knitout_code)
# Process instructions...

Example 2: Pattern Analysis

"""Basic example of loading a pattern from a knitout file and analysing it."""
from knitout_interpreter.run_knitout import run_knitout
from knitout_interpreter.knitout_execution import Knitout_Executer

# Load complex pattern
instructions, machine, graph = run_knitout("complex_pattern.knitout")

# Analyze with executer
executer = Knitout_Executer(instructions, machine)

# Print analysis
print("=== Pattern Analysis ===")
print(f"Total instructions: {len(instructions)}")
print(f"Execution time: {executer.execution_time} passes")
print(f"Width: {executer.right_most_position - executer.left_most_position + 1} needles")

# Analyze carriage passes
for i, cp in enumerate(executer.carriage_passes):
    print(f"Pass {i+1}: {cp}")

๐Ÿ“‹ Dependencies

Runtime Dependencies

  • python >= >=3.11,<3.13
  • parglare ^0.18 - Parser generator for knitout grammar
  • knit-graphs ^0.0.6 - Knitting graph data structures
  • virtual-knitting-machine ^0.0.13 - Virtual machine simulation
  • importlib_resources ^6.5. - Resource management

Development Dependencies

  • mypy - Static type checking
  • pre-commit - Code quality hooks
  • coverage - Test coverage measurement
  • sphinx - Documentation generation

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • McCann et al. for creating the Knitout specification
  • Northeastern University ACT Lab for supporting this research
  • This work has been supported by the following NSF Grants:
    • 2341880: HCC:SMALL:Tools for Programming and Designing Interactive Machine-Knitted Smart Textiles
    • 2327137: Collaborative Research: HCC: Small: End-User Guided Search and Optimization for Accessible Product Customization and Design

๐Ÿ“š Related Projects

๐Ÿ”— Links


Made with โค๏ธ by the Northeastern University ACT Lab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

knitout_interpreter-0.0.22.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

knitout_interpreter-0.0.22-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file knitout_interpreter-0.0.22.tar.gz.

File metadata

  • Download URL: knitout_interpreter-0.0.22.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for knitout_interpreter-0.0.22.tar.gz
Algorithm Hash digest
SHA256 21cde51ec34bc7952e4e5cf2628264f26db12c24c73183cee89748814b1600a1
MD5 56ae9f035c43f62da191ed6cfc826146
BLAKE2b-256 97f5fd7e1e3d294c6c756e31d80ac9040da8510d1ae33197945f7b40541d8255

See more details on using hashes here.

File details

Details for the file knitout_interpreter-0.0.22-py3-none-any.whl.

File metadata

  • Download URL: knitout_interpreter-0.0.22-py3-none-any.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for knitout_interpreter-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 213d6b0dac222eb876a6f57c9cb0135bb2bae963ef4683e53fd67ab1ff5208b1
MD5 040c4514b11d20efbc8ace0a1ff09d55
BLAKE2b-256 90c51798ff9bd77a299e4a74f19b3596ddd04899b0a1bb7b81bccb8386c5f4d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page