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_Instruction_Type
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_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
- knitout_interpreter.knitout_operations.knitout_instruction_factory module
- knitout_interpreter.knitout_operations.needle_instructions module
Module contents
knitout_operations: Individual knitout instruction implementations.
This module contains all the instruction classes that represent individual knitoutoperations. These classes implement the complete Knitout specification v2, providing Python objects for every type of instruction that can appear in a knitout file.
The instructions are organized into several categories based on their function:
- Needle Operations:
Instructions that operate on specific needles to manipulate loops and yarn. These form the core knitting operations and directly affect the fabric structure.
- Carrier Operations:
Instructions that manage yarn carriers - the system that supplies yarn to the knitting needles. These control yarn insertion and removal.
- Machine Control:
Instructions that control machine state, including bed alignment (racking), execution pauses, and other machine-level operations.
- Header Declarations:
Special instructions that appear at the beginning of knitout files to specify machine configuration, yarn properties, and other setup parameters.
- Base Classes:
Fundamental classes that provide common functionality and type definitions for all instruction types.
- Instruction Execution Model:
Each instruction class implements an execute() method that applies the instruction’s effects to a virtual knitting machine state. This allows for simulation, validation, and analysis of knitout programs before running them on physical machines.
Example
Working with specific instruction types:
>>> from knitout_interpreter.knitout_operations import Knit_Instruction, In_Instruction
>>> from virtual_knitting_machine.Knitting_Machine import Knitting_Machine
>>> from virtual_knitting_machine.machine_components.needles.Needle import Needle
>>> from virtual_knitting_machine.machine_components.yarn_management.Yarn_Carrier_Set import Yarn_Carrier_Set
>>>
>>> # Create machine and components
>>> machine = Knitting_Machine()
>>> needle = Needle(is_front=True, position=5)
>>> carriers = Yarn_Carrier_Set([1])
>>>
>>> # Create and execute instructions
>>> in_instruction = In_Instruction(1)
>>> knit_instruction = Knit_Instruction(needle, "rightward", carriers)
>>>
>>> in_instruction.execute(machine)
>>> knit_instruction.execute(machine)
Working with header declarations:
>>> from knitout_interpreter.knitout_operations import Machine_Header_Line, Gauge_Header_Line
>>>
>>> machine_header = Machine_Header_Line("SWG091N2")
>>> gauge_header = Gauge_Header_Line(15)
>>>
>>> # Headers can update machine configuration
>>> machine_header.execute(machine)
>>> gauge_header.execute(machine)
Instruction type checking and properties:
>>> from knitout_interpreter.knitout_operations import Knitout_Instruction_Type
>>>
>>> instruction_type = Knitout_Instruction_Type.Knit
>>> print(f"Requires carrier: {instruction_type.requires_carrier}")
>>> print(f"Is needle instruction: {instruction_type.is_needle_instruction}")
>>> print(f"Compatible with tuck: {instruction_type.compatible_pass(Knitout_Instruction_Type.Tuck)}")
- Module Organization:
needle_instructions.py: All needle-based operations (knit, tuck, xfer, etc.) carrier_instructions.py: Yarn carrier management operations Header_Line.py: Machine configuration and setup declarations Rack_Instruction.py: Bed alignment control Pause_Instruction.py: Execution pause control kick_instruction.py: Specialized kickback positioning knitout_instruction.py: Base classes and instruction type definitions Knitout_Line.py: Base classes for all knitout file lines
- Instruction Hierarchy:
Knitout_Line (base for all knitout file content) ├── Knitout_Instruction (base for executable instructions) │ ├── Needle_Instruction (needle-based operations) │ │ ├── Loop_Making_Instruction (creates loops) │ │ │ ├── Knit_Instruction │ │ │ ├── Tuck_Instruction │ │ │ └── Split_Instruction │ │ ├── Drop_Instruction │ │ ├── Xfer_Instruction │ │ ├── Miss_Instruction │ │ │ └── Kick_Instruction │ ├── Yarn_Carrier_Instruction (carrier operations) │ │ ├── In_Instruction / Out_Instruction │ │ └── Hook_Instruction │ │ ├── Inhook_Instruction / Outhook_Instruction │ │ └── Releasehook_Instruction │ ├── Rack_Instruction │ └── Pause_Instruction ├── Knitout_Header_Line (configuration declarations) │ ├── Machine_Header_Line │ ├── Gauge_Header_Line │ ├── Yarn_Header_Line │ ├── Carriers_Header_Line │ └── Position_Header_Line ├── Knitout_Comment_Line └── Knitout_Version_Line
- Usage Patterns:
- Import specific instruction types:
from knitout_interpreter.knitout_operations import Knit_Instruction, Tuck_Instruction
- Import base classes for extension:
from knitout_interpreter.knitout_operations import Knitout_Instruction, Needle_Instruction
- class knitout_interpreter.knitout_operations.Knit_Instruction(needle, direction, cs, comment=None)[source]
Bases:
Loop_Making_Instruction
Instruction for knitting a loop on a needle.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_knit(machine_state, needle, direction, cs, comment=None)[source]
Execute a knit instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
direction (str | Carriage_Pass_Direction) – The direction to execute in.
cs (Yarn_Carrier_Set) – The yarn carriers set to execute with.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Tuck_Instruction(needle, direction, cs, comment=None)[source]
Bases:
Loop_Making_Instruction
Instruction for tucking yarn on a needle without dropping existing loops.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_tuck(machine_state, needle, direction, cs, comment=None)[source]
Execute a tuck instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
direction (str | Carriage_Pass_Direction) – The direction to execute in.
cs (Yarn_Carrier_Set) – The yarn carriers set to execute with.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Split_Instruction(needle, direction, n2, cs, comment=None)[source]
Bases:
Loop_Making_Instruction
Instruction for splitting a loop between two needles.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_split(machine_state, needle, direction, cs, n2, comment=None)[source]
Execute a split instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
direction (str | Carriage_Pass_Direction) – The direction to execute in.
cs (Yarn_Carrier_Set) – The yarn carriers set to execute with.
n2 (Needle) – The second needle to execute to.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Drop_Instruction(needle, comment=None)[source]
Bases:
Needle_Instruction
Instruction for dropping loops from a needle.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_Drop(machine_state, needle, comment=None)[source]
Execute a drop instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Xfer_Instruction(needle, n2, comment=None, record_location=True)[source]
Bases:
Needle_Instruction
Instruction for transferring loops between needles.
- add_loop_crossing(left_loop, right_loop)[source]
Update loop crossing to show transfers crossing loops.
- Parameters:
left_loop (Machine_Knit_Loop) – The left loop involved in the crossing.
right_loop (Machine_Knit_Loop) – The right loop involved in the crossing.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_xfer(machine_state, needle, n2, comment=None)[source]
Execute a transfer instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
n2 (Needle) – The second needle to execute to.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Miss_Instruction(needle, direction, cs, comment=None)[source]
Bases:
Needle_Instruction
Instruction for positioning carriers above a needle without forming loops.
- execute(machine_state)[source]
Position the carrier above the given needle.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True indicating the operation completed successfully.
- Return type:
- static execute_miss(machine_state, needle, direction, cs, comment=None)[source]
Execute a miss instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle) – The needle to execute on.
direction (str | Carriage_Pass_Direction) – The direction to execute in.
cs (Yarn_Carrier_Set) – The yarn carriers set to execute with.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Kick_Instruction(position, direction, cs=None, comment=None)[source]
Bases:
Miss_Instruction
A subclass of the Miss_Instruction used to mark kickbacks added in dat-complication process.
- execute(machine_state)[source]
Position the carrier above the given front-bed needle position.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True indicating the operation completed successfully.
- Return type:
- static execute_kick(machine_state, needle, direction, cs, comment=None)[source]
Execute a kick instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
needle (Needle | int) – The needle or front-bed needle position to move the carrier set to.
direction (str | Carriage_Pass_Direction) – The direction to execute in.
cs (Yarn_Carrier_Set) – The yarn carriers set to execute with.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.In_Instruction(carrier, comment=None)[source]
Bases:
Yarn_Carrier_Instruction
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- class knitout_interpreter.knitout_operations.Out_Instruction(carrier, comment=None)[source]
Bases:
Yarn_Carrier_Instruction
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- class knitout_interpreter.knitout_operations.Inhook_Instruction(carrier_set, comment=None)[source]
Bases:
Hook_Instruction
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- class knitout_interpreter.knitout_operations.Outhook_Instruction(carrier_set, comment=None)[source]
Bases:
Hook_Instruction
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- class knitout_interpreter.knitout_operations.Releasehook_Instruction(carrier, comment=None, preferred_release_direction=None)[source]
Bases:
Hook_Instruction
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update.
- Return type:
- static execute_releasehook(machine_state, carrier, comment=None)[source]
Execute a ‘releasehook’ instruction to release a hooked carrier.
- Parameters:
- Returns:
The instruction that was executed.
- Return type:
- property preferred_release_direction: Carriage_Pass_Direction
Get the preferred direction to release this carrier.
- Returns:
The preferred direction to release this carrier in. Will default to leftward release.
- class knitout_interpreter.knitout_operations.Rack_Instruction(rack, comment=None)[source]
Bases:
Knitout_Instruction
Instruction for setting the rack alignment between front and back beds.
- __str__()[source]
Return string representation of the rack instruction.
- Returns:
String representation showing instruction type, rack value, and comment.
- Return type:
- property all_needle_rack: bool
Check if rack causes all-needle-knitting alignment.
- Returns:
True if rack causes all-needle-knitting alignment.
- execute(machine_state)[source]
Execute the rack instruction on the given machine.
- Parameters:
machine_state (Knitting_Machine) – The knitting machine to update with the rack instruction.
- Returns:
True if the machine state was updated, False if no change was needed.
- Return type:
- static execute_rack(machine_state, racking, comment=None)[source]
Execute a rack instruction immediately on the machine.
- Parameters:
- Returns:
The racking instruction that was executed.
- Return type:
- property rack: int
Get the integer value of rack alignment.
- Returns:
Integer value of rack alignment.
- static rack_instruction_from_int_specification(rack=0, all_needle_rack=False, comment=None)[source]
Create a rack instruction from integer specification.
Note: From Knitout Specification: Number indicating the offset of the front bed relative to the back bed. That is, at racking R, back needle index B is aligned to front needle index B+R. Needles are considered aligned if they can transfer. That is, at racking 2, it is possible to transfer from f3 to b1. May be fractional on some machines. E.g., on Shima machines, 0.25/-0.75 are used for all-needle knitting.
- Parameters:
- Returns:
Rack instruction configured with the specified parameters.
- Return type:
- class knitout_interpreter.knitout_operations.Pause_Instruction(comment=None)[source]
Bases:
Knitout_Instruction
Instruction for pausing the knitting machine.
- execute(machine_state)[source]
Execute the pause instruction.
- Parameters:
machine_state (Knitting_Machine) – The machine state (not modified by pause).
- Returns:
False as no update is caused by pauses.
- Return type:
- static execute_pause(machine_state, comment=None)[source]
Execute a pause instruction on the machine.
- Parameters:
machine_state (Knitting_Machine) – The current machine model to update.
comment (str | None) – Additional details to document in the knitout.
- Returns:
The instruction that was executed.
- Return type:
- class knitout_interpreter.knitout_operations.Machine_Header_Line(machine_type, comment=None)[source]
Bases:
Knitout_Header_Line
- class knitout_interpreter.knitout_operations.Gauge_Header_Line(gauge, comment=None)[source]
Bases:
Knitout_Header_Line
- class knitout_interpreter.knitout_operations.Yarn_Header_Line(carrier_id, plies, yarn_weight, color, comment=None)[source]
Bases:
Knitout_Header_Line
- class knitout_interpreter.knitout_operations.Carriers_Header_Line(carrier_ids, comment=None)[source]
Bases:
Knitout_Header_Line
- class knitout_interpreter.knitout_operations.Position_Header_Line(position, comment=None)[source]
Bases:
Knitout_Header_Line
- class knitout_interpreter.knitout_operations.Knitout_Header_Line_Type(value)[source]
Bases:
Enum
Enumeration of properties that can be set in the header.
- Machine = 'Machine'
- Gauge = 'Gauge'
- Yarn = 'Yarn'
- Position = 'Position'
- Carriers = 'Carriers'
- class knitout_interpreter.knitout_operations.Knitting_Machine_Header(knitting_machine)[source]
Bases:
object
A class structure for maintaining the relationship between header lines and knitting machine state.
This class manages the relationship between header lines read from a knitout file and the state of a given knitting machine.
- get_header_lines(version=2)[source]
Get a complete knitout header from the stored header lines.
- Parameters:
version (int) – The knitout version number to process with. Defaults to 2.
- Returns:
List of header lines that form a complete knitout header. This starts with a version line.
- Return type:
- set_header_by_specification(machine_specification)[source]
Set the header lines to produce the given machine specification.
- Parameters:
machine_specification (Knitting_Machine_Specification) – The machine specification to set this header to.
- update_header(header_line, update_machine=False)[source]
Update this header with the given header line.
- Parameters:
header_line (Knitout_Header_Line) – The header line to update this header with.
update_machine (bool) – If True, the header line will update the machine state to the new values in this header_line, if present. If False, the header line will only update this header if there is no explicitly set header line for that value. In this case, if the header line would require the machine state to update, a warning is raised.
- Returns:
True if this header is updated by the given header line.
- Return type:
Note
If update_machine is False, no updates are allowed and this will always return False. If the update would cause a change in the active machine, then a warning is raised, and it makes no changes to the machine state.
- knitout_interpreter.knitout_operations.get_machine_header(knitting_machine, version=2)[source]
Get a list of header lines that describe the given machine state.
- Parameters:
knitting_machine (Knitting_Machine) – The machine state to specify as a header.
version (int) – The desired knitout version of the header. Defaults to 2.
- Returns:
A list containing header lines and a version line that describes the given machine state.
- Return type:
- class knitout_interpreter.knitout_operations.Knitout_Instruction_Type(value)[source]
Bases:
Enum
Enumeration of knitout instruction types.
- static get_instruction(inst_str)[source]
Get the instruction type from a string.
- Parameters:
inst_str (str) – Instruction string to convert.
- Returns:
The corresponding Knitout_Instruction_Type enum value.
- Return type:
- property is_carrier_instruction: bool
Check if instruction operates on yarn carriers.
- Returns:
True if instruction operates on yarn carriers.
- property is_needle_instruction: bool
Check if instruction operates on needles.
- Returns:
True if operation operates on needles.
- property is_miss_instruction: bool
True if the operation is a miss and can occur in a miss instruction pass.
- Type:
Returns
- property in_knitting_pass: bool
Check if instruction can be done in a knit pass.
- Returns:
True if instruction can be done in a knit pass.
- property all_needle_instruction: bool
Check if instruction is compatible with all-needle knitting.
- Returns:
True if instruction is compatible with all-needle knitting.
- property directed_pass: bool
Check if instruction requires a direction.
- Returns:
True if instruction requires a direction.
- property requires_carrier: bool
Check if instruction requires a carrier.
- Returns:
True if instruction requires a carrier.
- property requires_second_needle: bool
Check if instruction requires a second needle.
- Returns:
True if instruction requires a second needle.
- property allow_sliders: bool
Check if this is a transfer instruction that can operate on sliders.
- Returns:
True if this is a transfer instruction that can operate on sliders.
- compatible_pass(other_instruction)[source]
Determine if instruction can share a machine pass with another instruction.
- Parameters:
other_instruction (Knitout_Instruction_Type) – The other instruction to check compatibility with.
- Returns:
True if both instructions could be executed in the same pass.
- Return type:
- In = 'in'
- Inhook = 'inhook'
- Releasehook = 'releasehook'
- Out = 'out'
- Outhook = 'outhook'
- Stitch = 'stitch'
- Rack = 'rack'
- Knit = 'knit'
- Tuck = 'tuck'
- Split = 'split'
- Drop = 'drop'
- Xfer = 'xfer'
- Miss = 'miss'
- Kick = 'kick'
- Pause = 'pause'
- class knitout_interpreter.knitout_operations.Knitout_Comment_Line(comment)[source]
Bases:
Knitout_Line
Represents a comment line in knitout.
- class knitout_interpreter.knitout_operations.Knitout_Version_Line(version=2, comment=None)[source]
Bases:
Knitout_Line
Represents a knitout version specification line.