knitout_interpreter.knitout_operations.carrier_instructions module

Knitout Operations that involve the yarn inserting system

class Yarn_Carrier_Instruction(*args, **kwargs)[source]

Bases: Knitout_Instruction

Super class of all instructions related to the yarn-insertion system.

__init__(carrier, comment=None)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

get_yarn(machine)[source]

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

get_carrier(machine)[source]

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

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 to the machine state. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

will_update_machine_state(machine_state)
Parameters:

machine_state (Knitting_Machine) – The machine state to test if this instruction will update it.

Returns:

True if this instruction will update the machine state. False, otherwise.

Return type:

bool

instruction_type: ClassVar[Knitout_Instruction_Type]
comment: str | None
class Hook_Instruction(*args, **kwargs)[source]

Bases: Yarn_Carrier_Instruction

Super class of all carrier instructions that involve the yarn-inserting hook.

__init__(carrier, comment=None, requires_clear_inserting_hook=True)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

property requires_clear_inserting_hook: bool

Returns: bool: True if this instruction will require the yarn-inserting hook to be clear. False otherwise.

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

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 to the machine state. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

will_update_machine_state(machine_state)
Parameters:

machine_state (Knitting_Machine) – The machine state to test if this instruction will update it.

Returns:

True if this instruction will update the machine state. False, otherwise.

Return type:

bool

instruction_type: ClassVar[Knitout_Instruction_Type]
comment: str | None
class In_Instruction(*args, **kwargs)[source]

Bases: Yarn_Carrier_Instruction

Represents in-instructions that bring in a carrier without involving the yarn-inserting hook.

instruction_type: ClassVar[Knitout_Instruction_Type] = 'in'
__init__(carrier, comment=None)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

will_update_machine_state(machine_state)[source]
Parameters:

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

Returns:

True if the carrier being brought in is not active so that the instruction will have an effect. False otherwise.

Return type:

bool

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 to the machine state. False, otherwise.

Return type:

bool

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None
class Inhook_Instruction(*args, **kwargs)[source]

Bases: Hook_Instruction

instruction_type: ClassVar[Knitout_Instruction_Type] = 'inhook'
__init__(carrier_set, comment=None)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

will_update_machine_state(machine_state)[source]
Parameters:

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

Returns:

True if the carrier being brought in is not active so that the instruction will have an effect. False otherwise.

Return type:

bool

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 to the machine state. False, otherwise.

Return type:

bool

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

property requires_clear_inserting_hook: bool

Returns: bool: True if this instruction will require the yarn-inserting hook to be clear. False otherwise.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None
class Releasehook_Instruction(*args, **kwargs)[source]

Bases: Hook_Instruction

An instruction that releases the starting tail of a carrier on the yarn-inserting hook.

instruction_type: ClassVar[Knitout_Instruction_Type] = 'releasehook'
__init__(carrier, comment=None, preferred_release_direction=Leftward<-)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier to execute with.

  • comment (str, optional) – Additional details to document in the knitout. Defaults to no comment.

  • preferred_release_direction (Carriage_Pass_Direction, optional) – The preferred direction of operations proceeding this releasehook. Defaults to Leftward release.

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.

will_update_machine_state(machine_state)[source]
Parameters:

machine_state (Knitting_Machine) – The machine state to test if this instruction will update it.

Returns:

True the machine state has a hooked carrier to release. False otherwise.

Return type:

bool

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 to the machine state. False, otherwise.

Return type:

bool

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

property requires_clear_inserting_hook: bool

Returns: bool: True if this instruction will require the yarn-inserting hook to be clear. False otherwise.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None
class Out_Instruction(*args, **kwargs)[source]

Bases: Yarn_Carrier_Instruction

An instruction that moves a carrier off of the machine bed without cutting the yarn.

instruction_type: ClassVar[Knitout_Instruction_Type] = 'out'
__init__(carrier, comment=None)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

will_update_machine_state(machine_state)[source]
Parameters:

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

Returns:

True if the carrier being outhooked is active and available to be removed. False, otherwise.

Return type:

bool

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 to the machine state. False, otherwise.

Return type:

bool

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None
class Outhook_Instruction(*args, **kwargs)[source]

Bases: Hook_Instruction

An instruction that uses the yarn-inserting hook to cut and remove an active carrier from the system.

instruction_type: ClassVar[Knitout_Instruction_Type] = 'outhook'
__init__(carrier_set, comment=None)[source]
Parameters:
  • carrier (int | Yarn_Carrier) – The carrier or carrier id of the carrier involved in the operation.

  • comment (str, optional) – The comment of the instruction.:

will_update_machine_state(machine_state)[source]
Parameters:

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

Returns:

True if the carrier being outhooked is active and available to be removed. False, otherwise.

Return type:

bool

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 by cutting the carrier. False, otherwise.

Return type:

bool

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property carrier: int | Yarn_Carrier

Returns: int | Yarn_Carrier: The carrier of the instruction.

property carrier_id: int

Returns: int: The id of the carrier of the instruction.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

get_carrier(machine)

Get the yarn carrier specified on the given machine.

Parameters:

machine (Knitting_Machine) – The knitting machine to get the carrier from.

Returns:

The yarn carrier specified on the given machine.

Return type:

Yarn_Carrier

get_yarn(machine)

Get the yarn on the specified carrier.

Parameters:

machine (Knitting_Machine) – The knitting machine to get yarn from.

Returns:

The yarn on the specified carrier on the given machine.

Return type:

Machine_Knit_Yarn

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

property requires_clear_inserting_hook: bool

Returns: bool: True if this instruction will require the yarn-inserting hook to be clear. False otherwise.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None