knitout_interpreter.knitout_execution_structures.Carriage_Pass module
Module containing the Carriage Pass class.
- class Carriage_Pass(*args, **kwargs)[source]
Bases:
Generic[Pass_Instruction_Type]Manages knitout operations that are organized in a single carriage pass.
- static __new__(cls, *args, **kwargs)[source]
Counts the number of carriage passes created while running a program. Ensures a unique identifier for each carriage pass.
- __init__(first_instruction, rack, all_needle_rack)[source]
Initialize a new carriage pass with the first instruction.
- Parameters:
first_instruction (Yarn_to_Needle_Instruction | Xfer_Instruction) – The first needle instruction in this carriage pass.
rack (int) – The rack position for this carriage pass.
all_needle_rack (bool) – Whether this pass uses all-needle racking.
- property first_instruction: Pass_Instruction_Type
Get the first instruction given to carriage pass.
- Returns:
First instruction given to carriage pass.
- Return type:
- property directed_pass: bool
Returns: bool: True if this pass is directed by a yarn-carrier movement.
- property last_instruction: Pass_Instruction_Type
Get the last instruction executed in the carriage pass.
- Returns:
Last instruction executed in the given carriage pass.
- Return type:
- property needles: list[Needle_Specification]
Returns: list[Needle_Specification]: Needles in order given by instruction set.
- property needle_slots: set[int]
Returns: set[int]: The needle slot indices of needles used in this carriage pass.
- property last_needle: Needle_Specification
Get the needle at the end of the ordered instructions.
- Returns:
Needle at the end of the ordered instructions.
- Return type:
Needle_Specification
- property first_needle: Needle_Specification
Returns: Needle_Specification: The needle at the beginning of the ordered instructions.
- property leftmost_slot: int
Returns: int: The slot index of the leftmost needle in this carriage pass.
- property rightmost_slot: int
Returns: int: The slot index of the rightmost needle in this carriage pass.
- property carriage_pass_range: tuple[int, int]
Returns: tuple[int, int]: The leftmost position and rightmost position in the carriage pass.
- property instruction_set: set[Pass_Instruction_Type]
Returns: set[Pass_Instruction_Type]: An unordered set of the instructions in the carriage pass.
- property rightward_sorted_needles: list[Needle_Specification]
Returns: list[Needle_Specification]: List of needles in the carriage pass sorted from left to right.
- property leftward_sorted_needles: list[Needle_Specification]
Returns: list[Needle_Specification]: List of needles in the carriage pass sorted from right to left.
- property sorted_needles: list[Needle_Specification]
Returns: list[Needle_Specification]: List of needles in carriage pass sorted by direction of carriage pass or from left to right if instructions are undirected.
- instruction_by_needle(needle)[source]
- Parameters:
needle (Needle_Specification) – The needle to find the instruction of.
- Returns:
The instruction that operates on the given needle.
- Return type:
Pass_Instruction_Type
- Raises:
KeyError – If the needle is not in the carriage pass.
- instruction_by_slot(slot)[source]
- Parameters:
slot (int) – The needle slot to find an instruction on.
- Returns:
The instruction that operates on the given slot. If both the front and back needle of the slot are used, returns a tuple of the front needle’s instruction then the back needle’s instruction.
- Return type:
Pass_Instruction_Type | tuple[Pass_Instruction_Type, Pass_Instruction_Type]
- Raises:
IndexError – If the slot is not in the carriage pass.
- instructions_by_needles(needles)[source]
- Parameters:
needles (Sequence[Needle_Specification]) – Needles involved in the carriage pass.
- Returns:
The ordered list of instructions that start from the given needles.
- Return type:
list[Pass_Instruction_Type]
- rack_instruction(comment='Racking for next carriage pass.')[source]
- Parameters:
comment (str, optional) – Comment to include with the racking instruction. Defaults to “Racking for next carriage pass.”
- Returns:
Racking instruction to set up this carriage pass.
- Return type:
- contains_instruction_type(instruction_type)[source]
Check if the carriage pass contains a specific instruction type.
- Parameters:
instruction_type (type(Needle_Instruction)) – Instruction type to consider.
- Returns:
True if the instruction type is used at least once in this carriage pass. False, otherwise.
- Return type:
- can_add_instruction(instruction, rack, all_needle_rack)[source]
Check if an instruction can be added to this carriage pass.
- Parameters:
instruction (Needle_Instruction) – The instruction to consider adding to the carriage pass.
rack (int) – The required racking of this instruction.
all_needle_rack (all_needle_rack) – The all_needle racking requirement for this instruction.
- Returns:
True if the instruction can be added to this carriage pass. Otherwise, False.
- Return type:
Notes
Requirements to add to Pass: * Instruction must be at the same racking as this carriage pass * The instruction’s needle cannot already be used in this pass. * The instruction must be of a compatible type with the instructions in this pass. * If the instruction is directed and uses a yarn carrier, these values must match.
If the pass is all-needle knit and the values may be on the same slot (i.e, front and back bed).
The slot of this instruction must come after the slot of the last instruction.
- add_instruction(instruction, rack, all_needle_rack)[source]
Attempt to add an instruction to the carriage pass.
- Parameters:
- Returns:
True if instruction was added to pass. Otherwise, False implies that the instruction cannot be added to this carriage pass.
- Return type:
- can_merge_pass(next_carriage_pass)[source]
- Parameters:
next_carriage_pass (Carriage_Pass) – A carriage pass that happens immediately after this carriage pass.
- Returns:
True if these can be merged into one carriage pass. False, otherwise.
- Return type:
- merge_carriage_pass(next_carriage_pass)[source]
Merge the next carriage pass into this carriage pass.
- Parameters:
next_carriage_pass (Carriage_Pass) – A carriage pass that happens immediately after this carriage pass.
- Returns:
True if the merge was successful. False, otherwise. TypeGuard guarantees that the merged pass has the same Pass_Instruction_Type as this pass.
- Return type:
bool, TypeGuard[Carriage_Pass[Pass_Instruction_Type]]
- add_kicks(kicks)[source]
Adds the given kick instructions to the carriage pass. These kicks can be added at any slot that is not currently occupied by an instruction.
- Parameters:
kicks (Iterable[Kick_Instruction]) – The kicks to add to the carriage pass.
- Raises:
ValueError – If adding kicks to a xfer pass without a specified direction or a kick uses a different carrier set than the one used by this carriage pass.
IndexError – If adding a kick at a slot that is already occupied by an instruction.
- execute(knitting_machine)[source]
Execute carriage pass with an implied racking operation on the given knitting machine.
Will default to ordering xfers in a rightward ascending direction.
- Parameters:
knitting_machine (Knitting_Machine) – The knitting machine to execute the carriage pass on.
- Returns:
A list of executed instructions from the carriage pass. Instructions that do not update the machine state are commented.
- Return type:
list[Pass_Instruction_Type | Rack_Instruction | Knitout_Comment_Line]
- __str__()[source]
Return string representation of the carriage pass.
- Returns:
String representation showing direction, instruction types, and details.
- Return type:
- __list__()[source]
Convert carriage pass to list of knitout lines.
- Returns:
The list of needle instructions that form this carriage pass.
- Return type:
- __len__()[source]
Get the number of instructions in the carriage pass.
- Returns:
Number of instructions in the carriage pass.
- Return type:
- __repr__()[source]
Return detailed representation of the carriage pass.
- Returns:
String representation of the internal instructions list.
- Return type:
- __iter__()[source]
Iterate over the instructions in the carriage pass.
- Returns:
Iterator over the instructions.
- Return type:
Iterator[Pass_Instruction_Type]
- __getitem__(index: int) Pass_Instruction_Type[source]
- __getitem__(index: slice) list[Pass_Instruction_Type]
Get instruction(s) by index or slice.
- 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]): ….
- carriage_pass_typed_to_first_instruction(first_instruction: Xfer_Instruction, rack: int, all_needle_rack: bool) Carriage_Pass[Xfer_Instruction][source]
- carriage_pass_typed_to_first_instruction(first_instruction: Split_Instruction, rack: int, all_needle_rack: bool) Carriage_Pass[Split_Instruction]
- carriage_pass_typed_to_first_instruction(first_instruction: Drop_Instruction, rack: int, all_needle_rack: bool) Carriage_Pass[Drop_Instruction]
- carriage_pass_typed_to_first_instruction(first_instruction: Knit_Pass_Instruction, rack: int, all_needle_rack: bool) Carriage_Pass[Knit_Pass_Instruction]
- carriage_pass_typed_to_first_instruction(first_instruction: Miss_Instruction, rack: int, all_needle_rack: bool) Carriage_Pass[Miss_Instruction]
- Parameters:
first_instruction (Needle_Instruction) – First instruction to carriage pass.
rack (int) – The racking of the carriage pass.
all_needle_rack (bool) – True if the carriage pass operates at an all needle rack.
- Returns:
The carriage pass typed to the type of the first instruction.
- Return type:
Carriage_Pass[Pass_Instruction_Type]