knitout_interpreter package
Subpackages
- knitout_interpreter.knitout_execution_structures package
- Submodules
- Module contents
Carriage_Pass
Carriage_Pass.__getitem__()
Carriage_Pass.__hash__()
Carriage_Pass.__iter__()
Carriage_Pass.__len__()
Carriage_Pass.__list__()
Carriage_Pass.__repr__()
Carriage_Pass.__str__()
Carriage_Pass.add_instruction()
Carriage_Pass.can_add_instruction()
Carriage_Pass.can_merge_pass()
Carriage_Pass.carriage_pass_range()
Carriage_Pass.compatible_with_pass_type()
Carriage_Pass.contains_instruction_type()
Carriage_Pass.direction
Carriage_Pass.execute()
Carriage_Pass.first_instruction
Carriage_Pass.instruction_set()
Carriage_Pass.instructions_by_needles()
Carriage_Pass.last_instruction
Carriage_Pass.last_needle
Carriage_Pass.leftward_sorted_needles()
Carriage_Pass.merge_carriage_pass()
Carriage_Pass.needles
Carriage_Pass.rack_instruction()
Carriage_Pass.rightward_sorted_needles()
Carriage_Pass.sorted_needles()
- knitout_interpreter.knitout_language package
- Submodules
- knitout_interpreter.knitout_language.Knitout_Context module
- knitout_interpreter.knitout_language.Knitout_Parser module
- knitout_interpreter.knitout_language.knitout_actions module
comment()
code_line()
magic_string()
header_line()
machine_op()
gauge_op()
yarn_op()
carriers_op()
position_op()
in_op()
inhook_op()
releasehook_op()
out_op()
outhook_op()
rack_op()
knit_op()
tuck_op()
miss_op()
kick_op()
split_op()
drop_op()
xfer_op()
pause_op()
identifier()
float_exp()
int_exp()
needle_id()
carrier_set()
- Module contents
- Submodules
- knitout_interpreter.knitout_operations package
- Submodules
- knitout_interpreter.knitout_operations.Header_Line module
- knitout_interpreter.knitout_operations.Knitout_Line module
- knitout_interpreter.knitout_operations.Pause_Instruction module
- knitout_interpreter.knitout_operations.Rack_Instruction module
- knitout_interpreter.knitout_operations.carrier_instructions module
- knitout_interpreter.knitout_operations.kick_instruction module
- knitout_interpreter.knitout_operations.knitout_instruction module
- knitout_interpreter.knitout_operations.knitout_instruction_factory module
- knitout_interpreter.knitout_operations.needle_instructions module
- Module contents
Knit_Instruction
Tuck_Instruction
Split_Instruction
Drop_Instruction
Xfer_Instruction
Miss_Instruction
Kick_Instruction
In_Instruction
Out_Instruction
Inhook_Instruction
Outhook_Instruction
Releasehook_Instruction
Rack_Instruction
Pause_Instruction
Machine_Header_Line
Gauge_Header_Line
Yarn_Header_Line
Carriers_Header_Line
Position_Header_Line
Knitout_Header_Line_Type
Knitting_Machine_Header
get_machine_header()
Knitout_Instruction_Type
Knitout_Instruction_Type.get_instruction()
Knitout_Instruction_Type.is_carrier_instruction
Knitout_Instruction_Type.is_needle_instruction
Knitout_Instruction_Type.is_miss_instruction
Knitout_Instruction_Type.in_knitting_pass
Knitout_Instruction_Type.all_needle_instruction
Knitout_Instruction_Type.directed_pass
Knitout_Instruction_Type.requires_carrier
Knitout_Instruction_Type.requires_second_needle
Knitout_Instruction_Type.allow_sliders
Knitout_Instruction_Type.compatible_pass()
Knitout_Instruction_Type.In
Knitout_Instruction_Type.Inhook
Knitout_Instruction_Type.Releasehook
Knitout_Instruction_Type.Out
Knitout_Instruction_Type.Outhook
Knitout_Instruction_Type.Stitch
Knitout_Instruction_Type.Rack
Knitout_Instruction_Type.Knit
Knitout_Instruction_Type.Tuck
Knitout_Instruction_Type.Split
Knitout_Instruction_Type.Drop
Knitout_Instruction_Type.Xfer
Knitout_Instruction_Type.Miss
Knitout_Instruction_Type.Kick
Knitout_Instruction_Type.Pause
Knitout_Comment_Line
Knitout_Version_Line
- Submodules
Submodules
- knitout_interpreter.knitout_execution module
Knitout_Executer
Knitout_Executer.version_line
Knitout_Executer.execution_time
Knitout_Executer.left_most_position
Knitout_Executer.right_most_position
Knitout_Executer.resulting_knit_graph
Knitout_Executer.carriage_passes
Knitout_Executer.test_and_organize_instructions()
Knitout_Executer.write_executed_instructions()
- knitout_interpreter.run_knitout module
Module contents
knitout_interpreter: A comprehensive library for interpreting knitout files.
This package provides tools for parsing, validating, and executing knitout files used to control automatic V-Bed knitting machines. It includes support for the complete Knitout specification v2 created by McCann et al.
The library bridges the gap between high-level knitting pattern descriptions and machine-level execution, providing comprehensive analysis and simulation capabilities.
- Core Functionality:
run_knitout(): Simple function to parse and execute knitout files
Knitout_Executer: Advanced class for detailed analysis and execution control
- For specialized functionality, import from submodules:
knitout_interpreter.knitout_operations: Individual instruction types
knitout_interpreter.knitout_language: Parsing and grammar support
knitout_interpreter.knitout_execution_structures: Execution data structures
Example
Basic usage - execute a knitout file:
>>> from knitout_interpreter.run_knitout import run_knitout
>>> instructions, machine, graph = run_knitout("pattern.k")
>>> print(f"Executed {len(instructions)} instructions")
Advanced analysis with detailed control:
>>> from knitout_interpreter import Knitout_Executer
>>> from knitout_interpreter.knitout_language.Knitout_Parser import parse_knitout
>>> from virtual_knitting_machine.Knitting_Machine import Knitting_Machine
>>>
>>> instructions = parse_knitout("pattern.k", pattern_is_file=True)
>>> executer = Knitout_Executer(instructions, Knitting_Machine())
>>> print(f"Execution time: {executer.execution_time} carriage passes")
>>> print(f"Width required: {executer.left_most_position} to {executer.right_most_position}")
- knitout_interpreter.run_knitout(knitout_file_name)[source]
Execute knitout instructions from a given file.
This function provides a convenient interface for processing a knitout file through the knitout interpreter, returning the executed instructions and resulting machine state and knit graph.
- Parameters:
knitout_file_name (str) – Path to the file that contains knitout instructions.
- Returns:
A 3-element tuple containing the executed instructions, final machine state, and knit graph. The first element is a list of Knitout_Line objects representing all processed instructions. The second element is a Knitting_Machine object containing the final state of the virtual knitting machine after execution. The third element is a Knit_Graph object representing the resulting fabric structure formed by the knitting operations.
- Return type:
Example
Basic usage:
instructions, machine, graph = run_knitout("pattern.k") print(f"Executed {len(instructions)} instructions") print(f"Machine has {len(machine.needle_beds)} needle beds") print(f"Graph contains {graph.node_count} nodes")
Note
The knitout file must be a valid knitout format file with proper headers and instructions.
- Raises:
FileNotFoundError – If the specified knitout file cannot be found.
ValueError – If the knitout file contains invalid syntax or instructions.
- class knitout_interpreter.Knitout_Executer(instructions, knitting_machine=None, accepted_error_types=None, knitout_version=2)[source]
Bases:
object
A class used to execute a set of knitout instructions on a virtual knitting machine.
- property carriage_passes: list[Carriage_Pass]
Get the carriage passes from this execution.
- Returns:
The carriage passes resulting from this execution in execution order.
- property execution_time: int
Get the execution time as measured by carriage passes.
- Returns:
Count of carriage passes in process as a measure of knitting time.
- property left_most_position: int | None
Get the leftmost needle position used in execution.
- Returns:
The position of the left most needle used in execution, or None if no needles were used.
- property resulting_knit_graph: Knit_Graph
Get the knit graph resulting from instruction execution.
- Returns:
Knit Graph that results from execution of these instructions.
- property right_most_position: int | None
Get the rightmost needle position used in execution.
- Returns:
The position of the right most needle used in the execution, or None if no needles were used.
- test_and_organize_instructions(accepted_error_types=None)[source]
Test the given execution and organize the instructions in the class structure.
This method processes all instructions, organizing them into carriage passes and handling any errors that occur during execution.
- Parameters:
accepted_error_types (list | None) – A list of exceptions that instructions may throw that can be resolved by commenting them out. Defaults to None.
- property version_line: Knitout_Version_Line
Get the version line for the executed knitout.
- Returns:
The version line for the executed knitout.