virtual_knitting_machine.machine_components.yarn_management.Yarn_Insertion_System module

A module containing Yarn Insertion System classes for managing yarn carriers on knitting machines. This module provides the Yarn_Insertion_System class which manages the complete yarn carrier system including carrier states, insertion hook operations, position tracking, and loop creation operations.

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

Bases: Machine_Component, Protocol[Machine_LoopT, Carrier_State_Type]

A protocol for the readable elements of a yarn-insertion system.

property carriers: list[Carrier_State_Type]

Returns: list[Yarn_Carrier_State]: The list of yarn carriers in this insertion system. The carriers are ordered from 1 to the number of carriers in the system.

property hook_position: int | None
Returns:

The needle slot of the yarn-insertion hook or None if the yarn-insertion hook is not active.

Return type:

None | int

Notes

The hook position will be None if its exact position is to the right of the edge of the knitting machine bed.

property hook_input_direction: Carriage_Pass_Direction | None

Returns: Carriage_Pass_Direction | None: The direction that the carrier was moving when the yarn-inserting hook was use. None if the yarn-inserting hook is not active.

property hooked_carrier: Carrier_State_Type | None

Returns: (Yarn_Carrier_State | None): The yarn-carrier currently on the yarn-inserting-hook or None if the hook is not active.

property searching_for_position: bool

Check if the inserting hook is active but at an undefined position.

Returns:

True if the inserting hook is active but at an undefined position, False otherwise.

Return type:

bool

property carrier_ids: list[int]

Get list of all carrier IDs in the carrier system.

Returns:

List of carrier ids in the carrier system.

Return type:

list[int]

property inserting_hook_available: bool

Check if the yarn inserting hook can be used.

Returns:

True if the yarn inserting hook can be used, False if in use.

Return type:

bool

property active_carriers: set[Carrier_State_Type]

Returns: set[Yarn_Carrier_State]: Set of carriers that are currently active (off the grippers).

property active_floats: dict[Machine_LoopT, Machine_LoopT]

Get dictionary of all active floats from all carriers in the system.

Returns:

Dictionary of loops that are active keyed to active yarn-wise neighbors, each key-value pair represents a directed float where k comes before v on the yarns in the system.

Return type:

dict[Machine_Knit_Loop, Machine_Knit_Loop]

conflicts_with_inserting_hook(needle)[source]

Check if a needle position conflicts with the inserting hook position.

Parameters:

needle (Needle_Specification) – The needle-position to check for compliance.

Returns:

True if inserting hook conflicts with a needle slot because the slot is to the right of the hook’s current position. False otherwise.

Return type:

bool

missing_carriers(carrier_ids)[source]
Parameters:

carrier_ids (Sequence[int | Yarn_Carrier_State]) – The carrier set to check for the inactive carriers.

Returns:

List of carrier ids that are not active (i.e., on grippers).

Return type:

list[int]

is_active(carrier_ids)[source]

Check if all carriers in the given set are active (not on the gripper).

Parameters:

carrier_ids (Sequence[int | Yarn_Carrier_State]) – List of carrier IDs to check.

Returns:

True if all carriers in set are active (not-on the gripper), Note: If an empty list of carriers is given, this will return true because the empty set is active.

Return type:

bool

yarn_is_loose(carrier_id)[source]
Parameters:

carrier_id (int | Yarn_Carrier_State) – The carrier to check for loose yarn.

Returns:

True if any yarn in yarn carrier set is loose (not on the inserting hook or tuck/knit on bed), False otherwise.

Return type:

bool

__contains__(item)[source]
Parameters:

item (int | Yarn_Carrier_State | Sequence[int | Yarn_Carrier_State]) – The carrier, carrier id, or sequence of carriers to search for in carriers in this yarn insertion system.

Returns:

True if all the given carriers are in the yarn insertion system. False otherwise.

Return type:

bool

__getitem__(item: int | Yarn_Carrier_State) Carrier_State_Type[source]
__getitem__(item: slice | Sequence[int | Yarn_Carrier_State] | Sequence[Yarn_Carrier_State] | Sequence[int]) list[Carrier_State_Type]

Get carrier(s) by ID, carrier object, carrier set, or list of IDs/carriers.

Parameters:

item (int | Yarn_Carrier | slice | Sequence[int | Yarn_Carrier]) – The identifier(s) for the carrier(s) to retrieve.

Returns:

Single carrier or list of carriers corresponding to the input.

Return type:

Yarn_Carrier | list[Yarn_Carrier]

Raises:

KeyError – If invalid carrier ID is provided or carrier index is out of range.

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__init__(*args, **kwargs)
handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]

Returns: Knitting_Machine_State: The knitting machine that owns this component.

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.

class Yarn_Insertion_System(knitting_machine, carrier_count=10)[source]

Bases: Yarn_Insertion_System_State[Machine_LoopT, Yarn_Carrier[Machine_LoopT]]

A class for managing the complete state of the yarn insertion system including all yarn carriers on the knitting machine. This system handles carrier positioning, activation states, insertion hook operations, and coordinates loop creation across multiple carriers. It provides comprehensive management of yarn carrier operations including bring-in, hook operations, and float management.

__init__(knitting_machine, carrier_count=10)[source]

Initialize the yarn insertion system with specified number of carriers.

Parameters:
  • knitting_machine (Knitting_Machine) – The knitting machine this system belongs to.

  • carrier_count (int, optional) – Number of yarn carriers to create. Defaults to 10.

property knitting_machine: Knitting_Machine[Machine_LoopT]

Returns: Knitting_Machine: The knitting machine that this system belongs to.

property carriers: list[Yarn_Carrier[Machine_LoopT]]

Returns: list[Yarn_Carrier]: The list of yarn carriers in this insertion system. The carriers are ordered from 1 to the number of carriers in the system.

property hook_position: int | None
Returns:

The needle slot of the yarn-insertion hook or None if the yarn-insertion hook is not active.

Return type:

None | int

Notes

The hook position will be None if its exact position is to the right of the edge of the knitting machine bed.

property hook_input_direction: Carriage_Pass_Direction | None

Returns: Carriage_Pass_Direction | None: The direction that the carrier was moving when the yarn-inserting hook was use. None if the yarn-inserting hook is not active.

property hooked_carrier: Yarn_Carrier[Machine_LoopT] | None

Returns: (Yarn_Carrier | None): The yarn-carrier currently on the yarn-inserting-hook or None if the hook is not active.

property searching_for_position: bool

Check if the inserting hook is active but at an undefined position.

Returns:

True if the inserting hook is active but at an undefined position, False otherwise.

Return type:

bool

bring_in(carrier_id)[source]

Bring in a yarn carrier without insertion hook (tail to gripper), yarn is considered loose until knit.

Parameters:

carrier_id (int | Yarn_Carrier) – Carrier ID to bring in.

inhook(carrier_id)[source]

Bring a yarn in with insertion hook, yarn is not loose after this operation.

Parameters:

carrier_id (int | Yarn_Carrier) – Carriers to bring in by id.

releasehook()[source]

Release the yarn inserting hook from whatever carrier is currently using it.

out(carrier_id)[source]

Move carrier to gripper, removing it from action but does not cut it loose.

Parameters:

carrier_id (int | Yarn_Carrier) – Carrier ID to move out.

Raises:

Hooked_Carrier_Exception – If carrier is currently connected to insertion hook.

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__contains__(item)
Parameters:

item (int | Yarn_Carrier_State | Sequence[int | Yarn_Carrier_State]) – The carrier, carrier id, or sequence of carriers to search for in carriers in this yarn insertion system.

Returns:

True if all the given carriers are in the yarn insertion system. False otherwise.

Return type:

bool

__getitem__(item)

Get carrier(s) by ID, carrier object, carrier set, or list of IDs/carriers.

Parameters:

item (int | Yarn_Carrier | slice | Sequence[int | Yarn_Carrier]) – The identifier(s) for the carrier(s) to retrieve.

Returns:

Single carrier or list of carriers corresponding to the input.

Return type:

Yarn_Carrier | list[Yarn_Carrier]

Raises:

KeyError – If invalid carrier ID is provided or carrier index is out of range.

property active_carriers: set[Carrier_State_Type]

Returns: set[Yarn_Carrier_State]: Set of carriers that are currently active (off the grippers).

property active_floats: dict[Machine_LoopT, Machine_LoopT]

Get dictionary of all active floats from all carriers in the system.

Returns:

Dictionary of loops that are active keyed to active yarn-wise neighbors, each key-value pair represents a directed float where k comes before v on the yarns in the system.

Return type:

dict[Machine_Knit_Loop, Machine_Knit_Loop]

property carrier_ids: list[int]

Get list of all carrier IDs in the carrier system.

Returns:

List of carrier ids in the carrier system.

Return type:

list[int]

conflicts_with_inserting_hook(needle)

Check if a needle position conflicts with the inserting hook position.

Parameters:

needle (Needle_Specification) – The needle-position to check for compliance.

Returns:

True if inserting hook conflicts with a needle slot because the slot is to the right of the hook’s current position. False otherwise.

Return type:

bool

handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

property inserting_hook_available: bool

Check if the yarn inserting hook can be used.

Returns:

True if the yarn inserting hook can be used, False if in use.

Return type:

bool

is_active(carrier_ids)

Check if all carriers in the given set are active (not on the gripper).

Parameters:

carrier_ids (Sequence[int | Yarn_Carrier_State]) – List of carrier IDs to check.

Returns:

True if all carriers in set are active (not-on the gripper), Note: If an empty list of carriers is given, this will return true because the empty set is active.

Return type:

bool

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

missing_carriers(carrier_ids)
Parameters:

carrier_ids (Sequence[int | Yarn_Carrier_State]) – The carrier set to check for the inactive carriers.

Returns:

List of carrier ids that are not active (i.e., on grippers).

Return type:

list[int]

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

outhook(carrier_id)[source]

Cut carrier yarn and move it to grippers with insertion hook, the carrier will no longer be active and is now loose.

Parameters:

carrier_id (int | Yarn_Carrier) – Carrier ID to cut and move out.

Raises:
  • Inserting_Hook_In_Use_Exception – If insertion hook is not available.

  • Hooked_Carrier_Exception – If carrier is already connected to insertion hook.

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.

yarn_is_loose(carrier_id)
Parameters:

carrier_id (int | Yarn_Carrier_State) – The carrier to check for loose yarn.

Returns:

True if any yarn in yarn carrier set is loose (not on the inserting hook or tuck/knit on bed), False otherwise.

Return type:

bool

position_carrier_at_needle(carrier_id, needle, direction=None)[source]

Update the needle-slot position of a specific carrier.

Parameters:
  • carrier_id (int | Yarn_Carrier) – The carrier to update.

  • needle (Needle_Specification | None) – The needle to position the carrier relative to.

  • direction (Carriage_Pass_Direction, optional) – The direction of the carrier movement. If this is not provided, the direction will be inferred.

Raises:

BLocked_By_Yarn_Inserting_Hook_Exception – If the yarn-inserting hook blocks this carrier movement.

make_loops(carrier_ids, needle, direction, **_loop_kwargs)[source]

Create loops using specified carriers on a needle, handling insertion hook positioning and float management.

Parameters:
Returns:

The set of loops made on this machine.

Return type:

list[Machine_Knit_Loop]