virtual_knitting_machine.Knitting_Machine_Snapshot module

A module containing the Knitting_Machine_Snapshot class.

class Knitting_Machine_Snapshot(machine_state)[source]

Bases: Knitting_Machine_State[Machine_LoopT, Yarn_Carrier_Snapshot]

A snapshot of the state of a knitting machine at the time an instance is created.

_machine_state

A reference to the current state of the knitting machine that this snapshot was created from. It will update after creation of the snapshot.

Type:

Knitting_Machine

__init__(machine_state)[source]
property violation_policy: Knitting_Machine_Error_Policy

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

property gauged_layers: int

Returns: int: The number of gauged layers the machine is set to.

property carriage: Carriage_Snapshot

Returns: Carriage_Snapshot: A snapshot of the carriage’s state at the time this snapshot was created.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification: The specification of the knitting machine this snapshot was created from.

property knit_graph: Knit_Graph[Machine_LoopT]
Returns:

The knit graph associated with the machine state.

Return type:

Knit_Graph

Notes

The knit graph does is a reference to the machine state and will be updated to the latest state of the knitting machine, past the point of this snapshot.

property last_loop_id: int | None

Returns: int | None: The id of the last loop created on the knitting machine’s knitgraph at the time the snapshot was created. None if no loops were in the knitgraph at that time.

property rack: int

Returns: int: The racking offset of the knitting machine at the time the snapshot was created.

property all_needle_rack: bool

Returns: bool: True if the knitting machine has all needle rack at the time the snapshot was created, False otherwise.

property front_bed: Needle_Bed_Snapshot

Returns: Needle_Bed_Snapshot: The snapshot of the front bed of needles and slider needles.

property back_bed: Needle_Bed_Snapshot

Returns: Needle_Bed_Snapshot: The snapshot of the back bed of needles and slider needles.

property carrier_system: Yarn_Insertion_System_Snapshot

Returns: Yarn_Insertion_System_Snapshot: The snapshot of the carrier system at the time of this snapshot.

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.

__contains__(item)
Parameters:

item (Needle_Specification | Machine_Knit_Loop | Yarn_Carrier_State | Sequence[int | Yarn_Carrier_State]) – The item to search for.

Returns:

True if the given needle or loop are on one of the needle beds or if the given carriers are all in the carrier system. Other items will return False.

Return type:

bool

__getitem__(item)

Access needles, carriers, or find needles holding loops on the machine.

Parameters:

item (Needle_Specification | Yarn_Carrier_State | Yarn_Carrier_Set | Sequence[int | Yarn_Carrier_State] | Machine_Knit_Loop) – A needle, yarn carrier, carrier set, or loop to reference in the machine.

Returns:

The needle on the machine at the given needle position, or if given yarn carrier information return the corresponding carrier or carriers on the machine, or if given a loop return the corresponding needle that holds this loop or None if the loop is not held on a needle.

Return type:

Needle | Yarn_Carrier_State | list[Yarn_Carrier_State] | None

Raises:

KeyError – If the item cannot be accessed from the machine.

__len__()

Get the needle bed width of the machine.

Returns:

The needle bed width of the machine.

Return type:

int

active_floats()
Returns:

List of all active floats between two active loops currently held on the needle beds.

Return type:

list[tuple[Machine_Knit_Loop, Machine_Knit_Loop]]

property active_loops: set[Machine_LoopT]

Returns: set[Machine_Knit_Loop]: The set of loops currently held on a needle.

all_loops()

Get list of all needles holding loops with front bed needles given first.

Returns:

List of all needles holding loops with front bed needles given first.

Return type:

list[Needle]

all_needles()

Get list of all needles with front bed needles given first.

Returns:

List of all needles with front bed needles given first.

Return type:

list[Needle]

all_slider_loops()

Get list of all slider needles holding loops with front bed sliders given first.

Returns:

List of all slider needles holding loops with front bed sliders given first.

Return type:

list[Slider_Needle]

all_sliders()

Get list of all slider needles with front bed sliders given first.

Returns:

List of all slider needles with front bed sliders given first.

Return type:

list[Slider_Needle]

back_loops()

Get list of back bed needles that currently hold loops.

Returns:

List of back bed needles that currently hold loops.

Return type:

list[Needle]

back_needles()

Get list of all back bed needles.

Returns:

List of all back bed needles.

Return type:

list[Needle]

back_slider_loops()

Get list of back slider needles that currently hold loops.

Returns:

List of back slider needles that currently hold loops.

Return type:

list[Slider_Needle]

back_sliders()

Get list of all back bed slider needles.

Returns:

List of slider needles on back bed.

Return type:

list[Slider_Needle]

front_loops()

Get list of front bed needles that currently hold loops.

Returns:

List of front bed needles that currently hold loops.

Return type:

list[Needle]

front_needles()

Get list of all front bed needles.

Returns:

List of all front bed needles.

Return type:

list[Needle]

front_slider_loops()

Get list of front slider needles that currently hold loops.

Returns:

List of front slider needles that currently hold loops.

Return type:

list[Slider_Needle]

front_sliders()

Get list of all front bed slider needles.

Returns:

List of slider needles on front bed.

Return type:

list[Slider_Needle]

get_aligned_needle(needle, aligned_slider=False)
Parameters:
  • needle (Needle_Specification) – The needle to find the aligned needle to.

  • aligned_slider (bool, optional) – If True, will return a slider needle. Defaults to False.

Returns:

Needle aligned with the given needle at current racking.

Return type:

Needle

Note

From Knitout Specification: Specification: at racking R, back needle index B is aligned to front needle index B+R, needles are considered aligned if they can transfer. At racking 2 it is possible to transfer from f3 to b1 using formulas F = B + R, R = F - B, B = F - R.

get_back_needle(position, is_slider=False)
Parameters:
  • position (int) – The position of the needle.

  • is_slider (bool) – True if the needle is on a slider. Defaults to False.

Returns:

The specified back bed needle.

Return type:

Needle[Machine_LoopT]

get_carrier(carrier)

Get the carrier or list of carriers owned by the machine at the given specification.

Parameters:

carrier (int | Yarn_Carrier_State | Sequence[int | Yarn_Carrier_State]) – The carrier defined by a given carrier, carrier_set, integer or list of integers to form a set.

Returns:

The carrier or list of carriers owned by the machine at the given specification.

Return type:

Carrier_State_Type | list[Carrier_State_Type]

get_front_needle(position, is_slider=False)
Parameters:
  • position (int) – The position of the needle.

  • is_slider (bool) – True if the needle is on a slider. Defaults to False.

Returns:

The specified front bed needle.

Return type:

Needle[Machine_LoopT]

get_needle_of_loop(loop)
Parameters:

loop (Machine_Knit_Loop) – The loop to search for.

Returns:

The needle holding the loop or None if it is not held.

Return type:

Needle | None

get_specified_needle(is_front, position, is_slider=False)
Parameters:
  • is_front (bool) – If True, get a front bed needle.:

  • position (int) – The position of the needle.

  • is_slider (bool, optional) – If True get a slider needle. Defaults to False.

Returns:

The specified needle on this machine.

Return type:

Needle[Machine_LoopT]

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.

has_loop(loop)
Parameters:

loop (Machine_Knit_Loop) – The loop to search for.

Returns:

True if the loop is held on a needle. False otherwise.

Return type:

bool

has_needle(needle)
Parameters:

needle (Needle_Specification) – The needle to search for.

Returns:

True if the given needle is on a needle bed. False otherwise.

Return type:

bool

loops_crossed_by_float(loop1, loop2)
Parameters:
Returns:

The set of machine knit loops that are held on needles crossed by the given float.

Return type:

set[Machine_Knit_Loop]

property max_rack: int

Get the maximum distance that the machine can rack.

Returns:

The maximum distance that the machine can rack.

Return type:

int

property needle_count: int

Get the needle width of the machine.

Returns:

The needle width of the machine.

Return type:

int

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 sliders_are_clear: bool

Check if no loops are on any slider needle and knitting can be executed.

Returns:

True if no loops are on a slider needle and knitting can be executed, False otherwise.

Return type:

bool

property slot_range: tuple[int, int]
Returns:

The range of needle slots holding loops. The first value is the left most slot. The second value is the right most slot.

Return type:

tuple[int, int]

Notes

If there are no active loops, the slot range is (0, 0).

valid_rack(front_pos, back_pos)

Check if transfer can be completed at current racking.

Parameters:
  • front_pos (int) – The front needle in the racking.

  • back_pos (int) – The back needle in the racking.

Returns:

True if the current racking can make this transfer, False otherwise.

Return type:

bool