InstructionStack¶
Bases: Sequence[InstructionLabel], Displayable
A list of InstructionLabel objects to execute.
This is intended to be an immutable list of InstructionLabel
objects to execute. Stack manipulations return a modified copy.
Each entry is cast through from_raw(), so a
stack can freely mix every supported raw shape: a bare global
instruction name, the succinct (instruction, patch_label) 2-tuple,
a full dict for anything needing more (extra kwargs, or multiple
patches via "patch_labels").
Examples:
>>> from loqs.core.instructions import InstructionStack
>>> stack = InstructionStack([
... "Init State", # bare global instruction
... ("H", "L0"), # tuple sugar, single patch
... {
... "instruction": "FT Logical X Measure Classical Decoder",
... "patch_label": "L0",
... "flagged_check": "XZIIZ",
... "flagged_check_order": [4, 0, 1],
... }, # dict, single patch + extra kwargs
... {
... "instruction": "CNOT Bookkeeping",
... "patch_labels": {"ctrl": "L0", "tgt": "L1"},
... }, # dict, multi-patch
... ])
>>> len(stack)
4
>>> stack[0]["instruction"]
'Init State'
>>> stack[1]["patch_label"]
'L0'
>>> stack[2]["flagged_check"]
'XZIIZ'
>>> stack[3]["patch_labels"]
{'ctrl': 'L0', 'tgt': 'L1'}
InstructionStack ¶
InstructionStack(instructions: InstructionStackLike = None) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instructions
|
InstructionStackLike
|
A sequence of |
None
|
append_instruction ¶
append_instruction(item: InstructionLabelLike) -> InstructionStack
Add an entry to the end of the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
InstructionLabelLike
|
The item to add |
required |
Returns:
| Type | Description |
|---|---|
InstructionStack
|
The modified stack |
append_instructions ¶
append_instructions(items: Sequence[InstructionLabelLike]) -> InstructionStack
Add a series of entries to the end of the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Sequence[InstructionLabelLike]
|
The items to add |
required |
Returns:
| Type | Description |
|---|---|
InstructionStack
|
The modified stack |
count¶
Inherited method from Sequence.
decode¶
Inherited static method from Serializable.decode().
delete_instruction ¶
delete_instruction(i: int) -> InstructionStack
Remove an entry from the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
The index to remove |
required |
Returns:
| Type | Description |
|---|---|
InstructionStack
|
The modified stack |
display¶
Inherited method from Displayable.display().
dump¶
Inherited method from Serializable.dump().
encode¶
Inherited static method from Serializable.encode().
index¶
Inherited method from Sequence.
insert_instruction ¶
insert_instruction(i: int, item: InstructionLabelLike) -> InstructionStack
Add an entry to a position in the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
The index of insertion |
required |
item
|
InstructionLabelLike
|
The item to add |
required |
Returns:
| Type | Description |
|---|---|
InstructionStack
|
The modified stack |
insert_instructions ¶
insert_instructions(i: int, items: Sequence[InstructionLabelLike]) -> InstructionStack
Add a series of entries to a position in the stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
The index of insertion |
required |
items
|
Sequence[InstructionLabelLike]
|
The items to add |
required |
Returns:
| Type | Description |
|---|---|
InstructionStack
|
The modified stack |
load¶
Inherited class method from Serializable.load().
pop_instruction ¶
pop_instruction() -> tuple[InstructionLabel, InstructionStack]
Remove and return the first entry on the stack.
Returns:
| Type | Description |
|---|---|
(InstructionLabel, InstructionStack)
|
The first instruction and modified stack without the first element |
read¶
Inherited class method from Serializable.read().
serialize_function¶
Inherited static method from Serializable.serialize_function().
write¶
Inherited method from Serializable.write().