virtual_knitting_machine.machine_components.yarn_management.Yarn_Carrier module
Yarn_Carrier representation module for managing individual yarn carriers on knitting machines. This module provides the Yarn_Carrier class which represents a single yarn carrier that can hold yarn, track position, and manage active/hooked states for knitting operations.
- class Yarn_Carrier_State(*args, **kwargs)[source]
Bases:
Relative_to_Needle_Bed,Protocol[Machine_LoopT]A class from which all read-only attributes and properties of a yarn-carrier can be accessed. This class defines common properties between yarn-carriers and yarn-carrier-snapshots.
- property yarn: Machine_Knit_Yarn[Machine_LoopT]
Returns: Machine_Knit_Yarn: The yarn held on this carrier.
- property starting_position: Needle_Bed_Position
Returns: Needle_Bed_Position: The default starting position for carriers.
- __lt__(other)[source]
Compare if this carrier ID is less than another carrier or integer.
- Parameters:
other (int | Yarn_Carrier_State) – The carrier or integer to compare with.
- Returns:
True if this carrier’s ID is less than the other.
- Return type:
- __eq__(other)[source]
Equality comparison of a carrier to another carrier or object representing a carrier. :param other: The carrier or object representing a carrier. :type other: int | Yarn_Carrier_State | Yarn_Carrier_Set | Sequence[int | Yarn_Carrier_State]
- Returns:
True if this carrier is equal to the other. Carrier sets are equal if they only contain this carrier.
- Return type:
- __hash__()[source]
Return hash value based on carrier ID.
- Returns:
Hash value of the carrier ID.
- Return type:
- __str__()[source]
Return string representation of the carrier.
- Returns:
String representation showing carrier ID and yarn if different from ID.
- Return type:
- __repr__()[source]
Return string representation of the carrier.
- Returns:
String representation of the carrier.
- Return type:
- __int__()[source]
Return integer representation of the carrier.
- Returns:
The carrier ID as an integer.
- Return type:
- 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)
- aligned_with_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned at the same slot, False otherwise.
- Return type:
- direction_to_slot(slot)
- Parameters:
slot (int) – The slot to find a direction towards.
- Returns:
The direction of carriage movement from this component to the slot or None if the slots are aligned.
- Return type:
Carriage_Pass_Direction | None
- 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.
- in_pass_direction(slot, direction)
- Parameters:
slot (int | Slotted_Position) – The slot following this slot in a carriage pass movement.
direction (Carriage_Pass_Direction) – The direction to test.
- Returns:
True if the given slot is after this slot in the given direction. False otherwise.
- Return type:
- property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]
Returns: Knitting_Machine_State: The knitting machine that owns this component.
- property last_direction: Carriage_Pass_Direction
Returns: Carriage_Pass_Direction: The last direction the object moved in.
- left_of_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned left of the given slot, False otherwise.
- Return type:
- property machine_is_all_needle_racked: bool
Returns: bool: True if the knitting machine is racked for all needle knitting.
- 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 position_on_bed: Needle_Bed_Position[Machine_LoopT]
Returns: Needle_Bed_Position: The position of the machine component relative to the needle bed.
- right_of_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned right of the given slot, False otherwise.
- Return type:
- 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 slot_number: int
The slot number indicates the front-bed alignment of the given needle. For front bed needles this is equivalent to the position. For back bed needles this is dependent on the racking alignment of the beds.
- Returns:
The slot number of the given component for the given racking.
- Return type:
Notes
Racking Calculations: * R = F - B * F = R + B * B = F - R.
- property violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.
- class Yarn_Carrier(carrier_id, machine_state, yarn_properties=None)[source]
Bases:
Yarn_Carrier_State[Machine_LoopT]A class representing an individual yarn carrier on a knitting machine. Yarn carriers hold yarn and can be moved to different positions on the machine, activated for knitting operations, and connected to insertion hooks for yarn manipulation. Each carrier tracks its state including position, active status, and hook connection.
- __init__(carrier_id, machine_state, yarn_properties=None)[source]
Initialize a yarn carrier with specified ID and optional yarn configuration.
- Parameters:
carrier_id (int) – Unique identifier for this yarn carrier.
yarn_properties (Yarn_Properties | None, optional) – Properties for creating new yarn if yarn parameter is None. Defaults to None.
machine_state (Knitting_Machine[Machine_LoopT] | None) – The machine state that owns this carrier or None.
- property knitting_machine: Knitting_Machine[Machine_LoopT]
Returns: Knitting_Machine_State: The knitting machine that owns this carrier.
- property carrier_id: int
Get the unique identifier of this carrier.
- Returns:
ID of carrier, corresponds to order in machine.
- Return type:
- property yarn: Machine_Knit_Yarn[Machine_LoopT]
Get the yarn held on this carrier.
- Returns:
The yarn held on this carrier.
- Return type:
- property position_on_bed: Needle_Bed_Position
Returns: Needle_Bed_Position: The current position of this carrier.
- property is_hooked: bool
Check if the carrier is connected to the insertion hook.
- Returns:
True if connected to inserting hook, False otherwise.
- Return type:
- set_position(needle, direction=None)[source]
Set the position of this carrier to the given needle or set it to be off the needle bed.
- Parameters:
needle (Needle | None) – The needle to position the carrier relative or None if it is off the needle bed.
direction (Carriage_Pass_Direction | None, optional) – The direction the carrier should be moving in. Defaults to None.
- Raises:
Use_Inactive_Carrier_Exception – If the carrier is not active when its position is being set.
- make_loop(needle, **_loop_kwargs)[source]
- Parameters:
needle (Needle[Machine_LoopT]) – The needle to form the loop on.
**_loop_kwargs (Any) – Additional keyword argument to pass to the loop.
- Returns:
The loop formed with the carrier on the given needle.
- Return type:
Machine_LoopT
- Raises:
Use_Inactive_Carrier_Exception – If the carrier is not active when forming the loop.
- bring_in()[source]
Record bring-in operation to activate the carrier without using insertion hook.
- Warns:
In_Active_Carrier_Warning – If carrier is already active.
In_Loose_Carrier_Warning – If carrier is bringing in a yarn that is neither on the yarn-inserting-hook nor looped on a needle.
- 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]): ….
- __eq__(other)
Equality comparison of a carrier to another carrier or object representing a carrier. :param other: The carrier or object representing a carrier. :type other: int | Yarn_Carrier_State | Yarn_Carrier_Set | Sequence[int | Yarn_Carrier_State]
- Returns:
True if this carrier is equal to the other. Carrier sets are equal if they only contain this carrier.
- Return type:
- __hash__()
Return hash value based on carrier ID.
- Returns:
Hash value of the carrier ID.
- Return type:
- __int__()
Return integer representation of the carrier.
- Returns:
The carrier ID as an integer.
- Return type:
- __lt__(other)
Compare if this carrier ID is less than another carrier or integer.
- Parameters:
other (int | Yarn_Carrier_State) – The carrier or integer to compare with.
- Returns:
True if this carrier’s ID is less than the other.
- Return type:
- __repr__()
Return string representation of the carrier.
- Returns:
String representation of the carrier.
- Return type:
- __str__()
Return string representation of the carrier.
- Returns:
String representation showing carrier ID and yarn if different from ID.
- Return type:
- aligned_with_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned at the same slot, False otherwise.
- Return type:
- direction_to_slot(slot)
- Parameters:
slot (int) – The slot to find a direction towards.
- Returns:
The direction of carriage movement from this component to the slot or None if the slots are aligned.
- Return type:
Carriage_Pass_Direction | None
- 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.
- in_pass_direction(slot, direction)
- Parameters:
slot (int | Slotted_Position) – The slot following this slot in a carriage pass movement.
direction (Carriage_Pass_Direction) – The direction to test.
- Returns:
True if the given slot is after this slot in the given direction. False otherwise.
- Return type:
- property last_direction: Carriage_Pass_Direction
Returns: Carriage_Pass_Direction: The last direction the object moved in.
- left_of_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned left of the given slot, False otherwise.
- Return type:
- property machine_is_all_needle_racked: bool
Returns: bool: True if the knitting machine is racked for all needle knitting.
- 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.
- right_of_slot(slot)
- Parameters:
slot (int | Slotted_Position) – The slot to compare to.
- Returns:
True if this is positioned right of the given slot, False otherwise.
- Return type:
- 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 slot_number: int
The slot number indicates the front-bed alignment of the given needle. For front bed needles this is equivalent to the position. For back bed needles this is dependent on the racking alignment of the beds.
- Returns:
The slot number of the given component for the given racking.
- Return type:
Notes
Racking Calculations: * R = F - B * F = R + B * B = F - R.
- property starting_position: Needle_Bed_Position
Returns: Needle_Bed_Position: The default starting position for carriers.
- property violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.