knitout_interpreter package
Subpackages
- knitout_interpreter.knitout_execution_structures package
- Submodules
- Module contents
Carriage_PassCarriage_Pass.instruction_set()Carriage_Pass.rightward_sorted_needles()Carriage_Pass.leftward_sorted_needles()Carriage_Pass.sorted_needles()Carriage_Pass.instructions_by_needles()Carriage_Pass.carriage_pass_range()Carriage_Pass.rack_instruction()Carriage_Pass.directionCarriage_Pass.needlesCarriage_Pass.first_instructionCarriage_Pass.last_instructionCarriage_Pass.last_needleCarriage_Pass.contains_instruction_type()Carriage_Pass.add_instruction()Carriage_Pass.compatible_with_pass_type()Carriage_Pass.can_add_instruction()Carriage_Pass.can_merge_pass()Carriage_Pass.merge_carriage_pass()Carriage_Pass.execute()Carriage_Pass.__str__()Carriage_Pass.__list__()Carriage_Pass.__len__()Carriage_Pass.__repr__()Carriage_Pass.__iter__()Carriage_Pass.__getitem__()Carriage_Pass.__hash__()
- 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_InstructionTuck_InstructionSplit_InstructionDrop_InstructionXfer_InstructionMiss_InstructionKick_InstructionIn_InstructionOut_InstructionInhook_InstructionOuthook_InstructionReleasehook_InstructionRack_InstructionPause_InstructionMachine_Header_LineGauge_Header_LineYarn_Header_LineCarriers_Header_LinePosition_Header_LineKnitout_Header_Line_TypeKnitting_Machine_Headerget_machine_header()Knitout_Instruction_TypeKnitout_Instruction_Type.InKnitout_Instruction_Type.InhookKnitout_Instruction_Type.ReleasehookKnitout_Instruction_Type.OutKnitout_Instruction_Type.OuthookKnitout_Instruction_Type.StitchKnitout_Instruction_Type.RackKnitout_Instruction_Type.KnitKnitout_Instruction_Type.TuckKnitout_Instruction_Type.SplitKnitout_Instruction_Type.DropKnitout_Instruction_Type.XferKnitout_Instruction_Type.MissKnitout_Instruction_Type.KickKnitout_Instruction_Type.PauseKnitout_Instruction_Type.get_instruction()Knitout_Instruction_Type.is_carrier_instructionKnitout_Instruction_Type.is_needle_instructionKnitout_Instruction_Type.in_knitting_passKnitout_Instruction_Type.all_needle_instructionKnitout_Instruction_Type.directed_passKnitout_Instruction_Type.requires_carrierKnitout_Instruction_Type.requires_second_needleKnitout_Instruction_Type.allow_slidersKnitout_Instruction_Type.compatible_pass()
Knitout_Comment_LineKnitout_Version_Line
- Submodules
Submodules
- knitout_interpreter.knitout_execution module
Knitout_ExecuterKnitout_Executer.version_lineKnitout_Executer.execution_timeKnitout_Executer.left_most_positionKnitout_Executer.right_most_positionKnitout_Executer.resulting_knit_graphKnitout_Executer.carriage_passesKnitout_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, accepted_error_types=None, knitout_version=2)[source]
Bases:
objectA class used to execute a set of knitout instructions on a virtual knitting machine.
- property version_line: Knitout_Version_Line
Get the version line for the executed knitout.
- Returns:
The version line for the executed knitout.
- 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 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.
- 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 carriage_passes: list[Carriage_Pass]
Get the carriage passes from this execution.
- Returns:
The carriage passes resulting from this execution in execution order.
- 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.