# knitout_interpreter.knitout_operations package

## Submodules

- knitout_interpreter.knitout_operations.Header_Line module
  - `Knitout_Header_Line_Type`
    - `Knitout_Header_Line_Type.Machine`
    - `Knitout_Header_Line_Type.Gauge`
    - `Knitout_Header_Line_Type.Yarn`
    - `Knitout_Header_Line_Type.Position`
    - `Knitout_Header_Line_Type.Carriers`
  - `Knitout_Header_Line`
    - `Knitout_Header_Line.updates_machine_state()`
  - `Machine_Header_Line`
    - `Machine_Header_Line.updates_machine_state()`
    - `Machine_Header_Line.execute()`
  - `Gauge_Header_Line`
    - `Gauge_Header_Line.updates_machine_state()`
    - `Gauge_Header_Line.execute()`
  - `Position_Header_Line`
    - `Position_Header_Line.updates_machine_state()`
    - `Position_Header_Line.execute()`
  - `Yarn_Header_Line`
    - `Yarn_Header_Line.updates_machine_state()`
    - `Yarn_Header_Line.execute()`
  - `Carriers_Header_Line`
    - `Carriers_Header_Line.updates_machine_state()`
    - `Carriers_Header_Line.execute()`
  - `Knitting_Machine_Header`
    - `Knitting_Machine_Header.update_header()`
    - `Knitting_Machine_Header.set_header_by_specification()`
    - `Knitting_Machine_Header.get_header_lines()`
  - `get_machine_header()`
- knitout_interpreter.knitout_operations.Knitout_Line module
  - `Knitout_Line`
    - `Knitout_Line.interrupts_carriage_pass`
    - `Knitout_Line.add_follow_comment()`
    - `Knitout_Line.has_comment`
    - `Knitout_Line.comment_str`
    - `Knitout_Line.execute()`
    - `Knitout_Line.injected`
    - `Knitout_Line.id_str()`
  - `Knitout_Version_Line`
  - `Knitout_Comment_Line`
    - `Knitout_Comment_Line.execute()`
- knitout_interpreter.knitout_operations.Pause_Instruction module
  - `Pause_Instruction`
    - `Pause_Instruction.execute()`
    - `Pause_Instruction.execute_pause()`
- knitout_interpreter.knitout_operations.Rack_Instruction module
  - `Rack_Instruction`
    - `Rack_Instruction.rack`
    - `Rack_Instruction.all_needle_rack`
    - `Rack_Instruction.rack_value`
    - `Rack_Instruction.__str__()`
    - `Rack_Instruction.execute()`
    - `Rack_Instruction.rack_instruction_from_int_specification()`
    - `Rack_Instruction.execute_rack()`
- knitout_interpreter.knitout_operations.carrier_instructions module
  - `Yarn_Carrier_Instruction`
    - `Yarn_Carrier_Instruction.get_yarn()`
    - `Yarn_Carrier_Instruction.get_carrier()`
  - `Hook_Instruction`
  - `In_Instruction`
    - `In_Instruction.execute()`
    - `In_Instruction.execute_in()`
  - `Inhook_Instruction`
    - `Inhook_Instruction.execute()`
    - `Inhook_Instruction.execute_inhook()`
  - `Releasehook_Instruction`
    - `Releasehook_Instruction.preferred_release_direction`
    - `Releasehook_Instruction.execute()`
    - `Releasehook_Instruction.execute_releasehook()`
  - `Out_Instruction`
    - `Out_Instruction.execute()`
    - `Out_Instruction.execute_out()`
  - `Outhook_Instruction`
    - `Outhook_Instruction.execute()`
    - `Outhook_Instruction.execute_outhook()`
- knitout_interpreter.knitout_operations.kick_instruction module
  - `Kick_Instruction`
    - `Kick_Instruction.position`
    - `Kick_Instruction.no_carriers`
    - `Kick_Instruction.execute()`
    - `Kick_Instruction.execute_kick()`
- 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.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_Instruction.execute()`
- knitout_interpreter.knitout_operations.knitout_instruction_factory module
  - `build_instruction()`
- knitout_interpreter.knitout_operations.needle_instructions module
  - `Needle_Instruction`
    - `Needle_Instruction.get_yarns()`
    - `Needle_Instruction.get_carriers()`
    - `Needle_Instruction.has_second_needle`
    - `Needle_Instruction.has_direction`
    - `Needle_Instruction.has_carrier_set`
    - `Needle_Instruction.implied_racking`
  - `Loop_Making_Instruction`
  - `Knit_Instruction`
    - `Knit_Instruction.execute()`
    - `Knit_Instruction.execute_knit()`
  - `Tuck_Instruction`
    - `Tuck_Instruction.execute()`
    - `Tuck_Instruction.execute_tuck()`
  - `Split_Instruction`
    - `Split_Instruction.execute()`
    - `Split_Instruction.execute_split()`
  - `Drop_Instruction`
    - `Drop_Instruction.execute()`
    - `Drop_Instruction.execute_Drop()`
  - `Xfer_Instruction`
    - `Xfer_Instruction.add_loop_crossing()`
    - `Xfer_Instruction.execute()`
    - `Xfer_Instruction.execute_xfer()`
  - `Miss_Instruction`
    - `Miss_Instruction.execute()`
    - `Miss_Instruction.execute_miss()`

## 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)

  Bases: `Loop_Making_Instruction`

  Instruction for knitting a loop on a needle.

  execute(machine_state)

    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:

      bool

  static execute_knit(machine_state, needle, direction, cs, comment=None)

    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:

      Knit_Instruction

class knitout_interpreter.knitout_operations.Tuck_Instruction(needle, direction, cs, comment=None)

  Bases: `Loop_Making_Instruction`

  Instruction for tucking yarn on a needle without dropping existing loops.

  execute(machine_state)

    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:

      bool

  static execute_tuck(machine_state, needle, direction, cs, comment=None)

    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:

      Tuck_Instruction

class knitout_interpreter.knitout_operations.Split_Instruction(needle, direction, n2, cs, comment=None)

  Bases: `Loop_Making_Instruction`

  Instruction for splitting a loop between two needles.

  execute(machine_state)

    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:

      bool

  static execute_split(machine_state, needle, direction, cs, n2, comment=None)

    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:

      Split_Instruction

class knitout_interpreter.knitout_operations.Drop_Instruction(needle, comment=None)

  Bases: `Needle_Instruction`

  Instruction for dropping loops from a needle.

  execute(machine_state)

    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:

      bool

  static execute_Drop(machine_state, needle, comment=None)

    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:

      Drop_Instruction

class knitout_interpreter.knitout_operations.Xfer_Instruction(needle, n2, comment=None, record_location=True)

  Bases: `Needle_Instruction`

  Instruction for transferring loops between needles.

  add_loop_crossing(left_loop, right_loop)

    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)

    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:

      bool

  static execute_xfer(machine_state, needle, n2, comment=None)

    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:

      Xfer_Instruction

class knitout_interpreter.knitout_operations.Miss_Instruction(needle, direction, cs, comment=None)

  Bases: `Needle_Instruction`

  Instruction for positioning carriers above a needle without forming loops.

  execute(machine_state)

    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:

      bool

  static execute_miss(machine_state, needle, direction, cs, comment=None)

    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:

      Miss_Instruction

class knitout_interpreter.knitout_operations.Kick_Instruction(position, direction, cs=None, comment=None)

  Bases: `Miss_Instruction`

  A subclass of the Miss_Instruction used to mark kickbacks added in dat-complication process.

  property position: int

    Returns: The position from the front bed to kick the carrier to.

  property no_carriers: bool

    Check if this is a soft-miss kickback with no carriers.

    Returns:

      True if this is a soft-miss kickback with no carriers. No carriers can be set with a null carrier set or a carrier set with a 0 carrier (not a valid index for a carrier).

  execute(machine_state)

    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:

      bool

  static execute_kick(machine_state, needle, direction, cs, comment=None)

    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:

      Miss_Instruction

class knitout_interpreter.knitout_operations.In_Instruction(carrier, comment=None)

  Bases: `Yarn_Carrier_Instruction`

  execute(machine_state)

    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:

      bool

  static execute_in(machine_state, carrier, comment=None)

    Execute an ‘in’ instruction to bring a carrier into the knitting area.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - carrier (int | Yarn_Carrier) – The carrier to execute with.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The instruction that was executed.

    Return type:

      In_Instruction

class knitout_interpreter.knitout_operations.Out_Instruction(carrier, comment=None)

  Bases: `Yarn_Carrier_Instruction`

  execute(machine_state)

    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:

      bool

  static execute_out(machine_state, carrier, comment=None)

    Execute an ‘out’ instruction to move a carrier out of the knitting area.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - carrier (int | Yarn_Carrier) – The carrier to execute with.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The instruction that was executed.

    Return type:

      Out_Instruction

class knitout_interpreter.knitout_operations.Inhook_Instruction(carrier_set, comment=None)

  Bases: `Hook_Instruction`

  execute(machine_state)

    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:

      bool

  static execute_inhook(machine_state, carrier, comment=None)

    Execute an ‘inhook’ instruction to hook a carrier into position.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - carrier (int | Yarn_Carrier) – The carrier to execute with.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The instruction that was executed.

    Return type:

      Inhook_Instruction

class knitout_interpreter.knitout_operations.Outhook_Instruction(carrier_set, comment=None)

  Bases: `Hook_Instruction`

  execute(machine_state)

    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:

      bool

  static execute_outhook(machine_state, carrier, comment=None)

    Execute an ‘outhook’ instruction to hook a carrier out of position.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - carrier (int | Yarn_Carrier) – The carrier to execute with.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The instruction that was executed.

    Return type:

      Outhook_Instruction

class knitout_interpreter.knitout_operations.Releasehook_Instruction(carrier, comment=None, preferred_release_direction=None)

  Bases: `Hook_Instruction`

  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.

  execute(machine_state)

    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:

      bool

  static execute_releasehook(machine_state, carrier, comment=None)

    Execute a ‘releasehook’ instruction to release a hooked carrier.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - carrier (int | Yarn_Carrier) – The carrier to execute with.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The instruction that was executed.

    Return type:

      Releasehook_Instruction

class knitout_interpreter.knitout_operations.Rack_Instruction(rack, comment=None)

  Bases: `Knitout_Instruction`

  Instruction for setting the rack alignment between front and back beds.

  property rack: int

    Get the integer value of rack alignment.

    Returns:

      Integer value of rack alignment.

  property all_needle_rack: bool

    Check if rack causes all-needle-knitting alignment.

    Returns:

      True if rack causes all-needle-knitting alignment.

  property rack_value: float

    Get the rack value including all-needle-knitting alignment.

    Returns:

      The value of the rack including all-needle-knitting alignment as float specification.

  __str__()

    Return string representation of the rack instruction.

    Returns:

      String representation showing instruction type, rack value, and comment.

    Return type:

      str

  execute(machine_state)

    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:

      bool

  static rack_instruction_from_int_specification(rack=0, all_needle_rack=False, comment=None)

    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:

      - rack (int) – Integer racking value (default 0).

      - all_needle_rack (bool) – Whether to use all-needle knitting alignment (default False).

      - comment (None | str) – Optional comment to include with the instruction.

    Returns:

      Rack instruction configured with the specified parameters.

    Return type:

      Rack_Instruction

  static execute_rack(machine_state, racking, comment=None)

    Execute a rack instruction immediately on the machine.

    Parameters:

      - machine_state (Knitting_Machine) – The current machine model to update.

      - racking (float) – The new racking to set the machine to.

      - comment (str | None) – Additional details to document in the knitout.

    Returns:

      The racking instruction that was executed.

    Return type:

      Rack_Instruction

class knitout_interpreter.knitout_operations.Pause_Instruction(comment=None)

  Bases: `Knitout_Instruction`

  Instruction for pausing the knitting machine.

  execute(machine_state)

    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:

      bool

  static execute_pause(machine_state, comment=None)

    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:

      Pause_Instruction

class knitout_interpreter.knitout_operations.Machine_Header_Line(machine_type, comment=None)

  Bases: `Knitout_Header_Line`

  updates_machine_state(machine_state)

    Check if this header would update the given machine state.

    Parameters:

      machine_state (Knitting_Machine) – The machine state to check against.

    Returns:

      True if this header would update the given machine state, False otherwise.

    Return type:

      bool

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Gauge_Header_Line(gauge, comment=None)

  Bases: `Knitout_Header_Line`

  updates_machine_state(machine_state)

    Check if this header would update the given machine state.

    Parameters:

      machine_state (Knitting_Machine) – The machine state to check against.

    Returns:

      True if this header would update the given machine state, False otherwise.

    Return type:

      bool

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Yarn_Header_Line(carrier_id, plies, yarn_weight, color, comment=None)

  Bases: `Knitout_Header_Line`

  updates_machine_state(machine_state)

    Check if this header would update the given machine state.

    Parameters:

      machine_state (Knitting_Machine) – The machine state to check against.

    Returns:

      True if this header would update the given machine state, False otherwise.

    Return type:

      bool

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Carriers_Header_Line(carrier_ids, comment=None)

  Bases: `Knitout_Header_Line`

  updates_machine_state(machine_state)

    Check if this header would update the given machine state.

    Parameters:

      machine_state (Knitting_Machine) – The machine state to check against.

    Returns:

      True if this header would update the given machine state, False otherwise.

    Return type:

      bool

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Position_Header_Line(position, comment=None)

  Bases: `Knitout_Header_Line`

  updates_machine_state(machine_state)

    Check if this header would update the given machine state.

    Parameters:

      machine_state (Knitting_Machine) – The machine state to check against.

    Returns:

      True if this header would update the given machine state, False otherwise.

    Return type:

      bool

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Knitout_Header_Line_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

  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)

  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.

  update_header(header_line, update_machine=False)

    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:

      bool

    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.

  set_header_by_specification(machine_specification)

    Set the header lines to produce the given machine specification.

    Parameters:

      machine_specification (Knitting_Machine_Specification) – The machine specification to set this header to.

  get_header_lines(version=2)

    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:

      list[Knitout_Line]

knitout_interpreter.knitout_operations.get_machine_header(knitting_machine, version=2)

  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:

    list[Knitout_Line]

class knitout_interpreter.knitout_operations.Knitout_Instruction_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

  Bases: `Enum`

  Enumeration of knitout instruction types.

  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'
  static get_instruction(inst_str)

    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:

      Knitout_Instruction_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 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)

    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:

      bool

class knitout_interpreter.knitout_operations.Knitout_Comment_Line(comment)

  Bases: `Knitout_Line`

  Represents a comment line in knitout.

  execute(machine_state)

    Execute the instruction on the machine state.

    Parameters:

      machine_state (Knitting_Machine) – The knitting machine state to update.

    Returns:

      True if the process completes an update.

    Return type:

      bool

class knitout_interpreter.knitout_operations.Knitout_Version_Line(version=2, comment=None)

  Bases: `Knitout_Line`

  Represents a knitout version specification line.