virtual_knitting_machine.machine_components.yarn_management.Yarn_Carrier_Snapshot module

Module containing Yarn Carrier Snapshot class

class Yarn_Carrier_Snapshot(yarn_carrier, machine_snapshot)[source]

Bases: Yarn_Carrier_State[Machine_LoopT]

A snapshot of the state of a carrier at the time this instance was created.

__init__(yarn_carrier, machine_snapshot)[source]
property knitting_machine: Knitting_Machine_Snapshot[Machine_LoopT]

Returns: Knitting_Machine_Snapshot: The knitting machine snapshot that this system belongs to.

property last_loop_id: int | None

Returns: int | None: The last loop formed on the yarn of this carrier or None if it had not formed a loop yet.

property yarn: Machine_Knit_Yarn[Machine_LoopT]

Returns: Machine_Knit_Yarn: The yarn held on this carrier.

property position_on_bed: Needle_Bed_Position

Returns: Needle_Bed_Position: The position of the machine component relative to the needle bed.

property is_active: bool

Returns: bool: True if carrier is active, False otherwise.

property is_hooked: bool

Returns: bool: True if connected to inserting hook, False otherwise.

property carrier_id: int

Returns: int: ID of carrier, corresponds to order in machine.

loop_made_before_snapshot(loop)[source]
Parameters:

loop (int | Machine_Knit_Loop) – The loop (or loop_id) to compare to the timing of this snapshot.

Returns:

True if the given loop was formed prior to the snapshot, False otherwise.

Return type:

bool

Notes

This program assumes that the loop belongs to the knitgraph rendered by this knitting machine.

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:

bool

__hash__()

Return hash value based on carrier ID.

Returns:

Hash value of the carrier ID.

Return type:

int

__int__()

Return integer representation of the carrier.

Returns:

The carrier ID as an integer.

Return type:

int

__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:

bool

__repr__()

Return string representation of the carrier.

Returns:

String representation of the carrier.

Return type:

str

__str__()

Return string representation of the carrier.

Returns:

String representation showing carrier ID and yarn if different from ID.

Return type:

str

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:

bool

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:
Returns:

True if the given slot is after this slot in the given direction. False otherwise.

Return type:

bool

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:

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.

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:

bool

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:

int

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.