virtual_knitting_machine.Knitting_Machine module
Module containing the Knitting_Machine class for virtual knitting machine representation and operations.
This module provides the main Knitting_Machine class which serves as the central coordinator for all knitting operations, managing needle beds, carriage movement, yarn carriers, and knit graph construction.
- class Knitting_Machine(machine_specification=Knitting_Machine_Specification(machine=SWG091N2, gauge=15, position=Right, carrier_count=10, needle_count=540, maximum_rack=4, maximum_float=20, maximum_loop_hold=4, hook_size=5), knit_graph=None)[source]
Bases:
object
A virtual representation of a V-Bed WholeGarment knitting machine.
This class provides comprehensive functionality for simulating knitting operations including needle management, carriage control, yarn carrier operations, racking, and knit graph construction with support for all standard knitting operations like knit, tuck, transfer, split, and miss.
- machine_specification
The specification to build this machine from.
- knit_graph
The knit graph that has been formed on the machine.
- Type:
Knit_Graph
- Parameters:
machine_specification (
Knitting_Machine_Specification
)knit_graph (
Optional
[Knit_Graph
])
- __init__(machine_specification=Knitting_Machine_Specification(machine=SWG091N2, gauge=15, position=Right, carrier_count=10, needle_count=540, maximum_rack=4, maximum_float=20, maximum_loop_hold=4, hook_size=5), knit_graph=None)[source]
Initialize a virtual knitting machine with specified configuration.
- Parameters:
machine_specification (Knitting_Machine_Specification, optional) – Configuration parameters for the machine. Defaults to Knitting_Machine_Specification().
knit_graph (Knit_Graph | None, optional) – Existing knit graph to use, creates new one if None. Defaults to None.
- property needle_count: int
Get the needle width of the machine.
- Returns:
The needle width of the machine.
- Return type:
- property max_rack: int
Get the maximum distance that the machine can rack.
- Returns:
The maximum distance that the machine can rack.
- Return type:
- __len__()[source]
Get the needle bed width of the machine.
- Returns:
The needle bed width of the machine.
- Return type:
- copy(starting_state=None)[source]
Create a crude copy of this machine state with all relevant yarns inhooked and loops formed on required locations.
- Parameters:
starting_state (Knitting_Machine | None, optional) – A machine state to copy into, otherwise creates a new machine state with the same machine specification as this machine. Defaults to None.
- Returns:
A copy of the current machine state.
- Return type:
Note
This copy does not guarantee continuity of the knitgraph structure or history, it only ensures loops and carriers are correctly positioned to mimic the current state.
- property carrier_system: Yarn_Insertion_System
Get the carrier system used by the knitting machine.
- Returns:
The carrier system used by the knitting machine.
- Return type:
- property carriage: Carriage
Returns: Carriage: The carriage that activates needle operations on this machine.
- property front_bed: Needle_Bed
Returns: Needle_Bed: The front bed of needles and slider needles in this machine.
- property back_bed: Needle_Bed
Returns: Needle_Bed: The back bed of needles and slider needles in this machine.
- get_needle_of_loop(loop)[source]
Get the needle holding the loop or None if it is not held.
- 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:
None | Needle
- property all_needle_rack: bool
Check if racking is aligned for all needle knitting.
- Returns:
True if racking is aligned for all needle knitting, False otherwise.
- Return type:
- property rack: int
Get the current rack value of the machine.
- Returns:
The current rack value of the machine.
- Return type:
- get_carrier(carrier)[source]
Get the carrier or list of carriers owned by the machine at the given specification.
- Parameters:
carrier (int | Yarn_Carrier | Yarn_Carrier_Set | list[int | Yarn_Carrier]) – 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:
- __getitem__(item)[source]
Access needles, carriers, or find needles holding loops on the machine.
- Parameters:
item (Needle | tuple[bool, int, bool] | tuple[bool, int] | Yarn_Carrier | Yarn_Carrier_Set | list[int | Yarn_Carrier] | 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 | list[Yarn_Carrier] | None
- Raises:
KeyError – If the item cannot be accessed from the machine.
- update_rack(front_pos, back_pos)[source]
Update the current racking to align front and back needle positions.
- static get_rack(front_pos, back_pos)[source]
Calculate racking between front and back position using formula R = F - B, F = R + B, B = F - R.
- get_aligned_needle(needle, aligned_slider=False)[source]
Get the needle aligned with the given needle at current racking.
- Parameters:
- Returns:
Needle aligned with the given needle at current racking.
- Return type:
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.
- static get_transfer_rack(start_needle, target_needle)[source]
Calculate the racking value needed to make transfer between start and target needle.
- Parameters:
- Returns:
Racking value needed to make transfer between start and target needle, None if no racking can be made because needles are on the same bed.
- Return type:
int | None
- sliders_are_clear()[source]
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:
- in_hook(carrier_id)[source]
Declare that the in_hook for this yarn carrier is in use.
- Parameters:
carrier_id (int | Yarn_Carrier) – The yarn_carrier to bring in.
- Return type:
- release_hook()[source]
Declare that the in-hook is not in use but yarn remains in use.
- Return type:
- out_hook(carrier_id)[source]
Declare that the yarn is no longer in service and will need to be in-hooked to use.
- Parameters:
carrier_id (int | Yarn_Carrier) – The yarn carrier to remove from service.
- Return type:
- bring_in(carrier_id)[source]
Bring the yarn carrier into action.
- Parameters:
carrier_id (int | Yarn_Carrier) – The yarn carrier to bring in.
- Return type:
- out(carrier_id)[source]
Move the yarn_carrier out of action.
- Parameters:
carrier_id (int | Yarn_Carrier) – The yarn carrier to move out.
- Return type:
- tuck(carrier_set, needle, direction)[source]
Place loops made with carriers in the carrier set on the given needle.
- Parameters:
carrier_set (Yarn_Carrier_Set) – Set of yarns to make loops with.
needle (Needle) – Needle to make loops on.
direction (Carriage_Pass_Direction) – The direction to tuck in.
- Returns:
List of new loops made by tucking.
- Return type:
- knit(carrier_set, needle, direction)[source]
Form new loops from the carrier set by pulling them through all loops on the given needle.
Drop the existing loops and hold the new loops on the needle.
- Parameters:
carrier_set (Yarn_Carrier_Set) – Set of yarns to make loops with.
needle (Needle) – Needle to knit on.
direction (Carriage_Pass_Direction) – The direction to knit in.
- Returns:
Tuple containing list of loops stitched through and dropped off needle by knitting process, and list of loops formed in the knitting process.
- Return type:
- Warns:
Knit_on_Empty_Needle_Warning – If attempting to knit on a needle with no loops.
- drop(needle)[source]
Drop all loops currently on given needle.
- Parameters:
needle (Needle) – The needle to drop from.
- Returns:
The list of loops dropped.
- Return type:
Note
The direction of drop operations is not recorded, just like transfer operations. This enables easy tracking of relative movements that involve carriers.
- xfer(starting_needle, to_slider=False, from_split=False)[source]
Move all loops on starting_needle to aligned needle at current racking.
- Parameters:
- Returns:
The list of loops that are transferred.
- Return type:
- split(carrier_set, starting_needle, direction)[source]
Pull a loop formed in direction by the yarns in carriers through the loops on needle.
Transfer the old loops to opposite-bed needle in the process.
- Parameters:
carrier_set (Yarn_Carrier_Set) – Set of yarns to make loops with.
starting_needle (Needle) – The needle to transfer old loops from and to form new loops on.
direction (Carriage_Pass_Direction) – The carriage direction for the split operation.
- Returns:
Tuple containing the list of loops created by the split and the list of loops transferred.
- Return type:
Note
From the Knitout Documentation: Splitting with an empty carrier set will transfer. This transfers loops on starting needle to aligned needle at this racking then forms new loops pulled through the transferred loops and holds them on the starting needle.
- miss(carrier_set, needle, direction)[source]
Set the carrier positions to hover above the given needle.
- Parameters:
carrier_set (Yarn_Carrier_Set) – Set of yarns to move.
needle (Needle) – Needle to position the carriers from.
direction (Carriage_Pass_Direction) – The carriage direction for the miss operation.
- Return type:
- front_sliders()[source]
Get list of all front bed slider needles.
- Returns:
List of slider needles on front bed.
- Return type:
- back_sliders()[source]
Get list of all back bed slider needles.
- Returns:
List of slider needles on back bed.
- Return type:
- front_slider_loops()[source]
Get list of front slider needles that currently hold loops.
- Returns:
List of front slider needles that currently hold loops.
- Return type:
- back_slider_loops()[source]
Get list of back slider needles that currently hold loops.
- Returns:
List of back slider needles that currently hold loops.
- Return type:
- all_sliders()[source]
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: