loom_rotated_surface_code.applicator.merge
Copyright 2024 Entropica Labs Pte Ltd
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- loom_rotated_surface_code.applicator.merge.create_merge_2_body_stabilizers(blocks, merge_orientation, merge_distance, filling_upper_left_qubit, pauli)[source]
Create the new 2-body stabilizers located at the merged boundaries.
- Parameters:
blocks (tuple[RotatedSurfaceCode, RotatedSurfaceCode]) – blocks to merge.
merge_orientation (Orientation) – Orientation of the merge.
merge_distance (int) – Distance between the two blocks in the direction of the merge. A distance m means that there are m-1 rows/columns of data qubits between the two blocks to merge.
filling_upper_left_qubit (tuple[int, int]) – Upper left qubit of the filling region.
pauli (str) – Pauli string of the new stabilizers.
- Returns:
New left and right boundary stabilizers if the merge is horizontal, new top and bottom boundary stabilizers if the merge is vertical.
- Return type:
tuple[list[Stabilizer], list[Stabilizer]]
- loom_rotated_surface_code.applicator.merge.create_merge_circuit(interpretation_step, blocks, operation, qubits_to_reset, boundary_type)[source]
Create the circuit for the merge operation.
- Parameters:
interpretation_step (InterpretationStep) – Interpretation step containing the blocks to merge.
blocks (tuple[RotatedSurfaceCode, RotatedSurfaceCode]) – Blocks to merge.
operation (Merge) – Descriptor of the merge operation to perform.
qubits_to_reset (tuple[tuple[int, ...], ...]) – Qubits to reset during the merge operation.
boundary_type (str) – Type of boundary to merge.
- Returns:
Circuit for the merge operation.
- Return type:
- loom_rotated_surface_code.applicator.merge.create_syndromes(interpretation_step, qubits_to_reset, reset_type, new_stabilizers, new_stabs_increased_weight, merged_block)[source]
Creates the new syndromes for the stabilizers that are reset.
- Parameters:
interpretation_step (InterpretationStep) – Interpretation step to which we add the new syndromes.
qubits_to_reset (tuple[tuple[int, int, int], ...]) – Tuple of qubits that are reset during the merge
reset_type (
str) – Pauli type of the reset, this gives information on which stabilizer is reset in a deterministic state.new_stabilizers (tuple[Stabilizer, ...]) – Stabilizers created by the merge operation.
new_stabs_increased_weight (
tuple[Stabilizer,...]) – Stabilizers that grew from a previous 2-body of the initial blocks.merged_block (Block) – The newly merged block.
- Returns:
Reference syndromes of the reset stabilizers.
- Return type:
tuple[Syndrome, …]
- loom_rotated_surface_code.applicator.merge.find_data_qubits_between(qubit1, qubit2)[source]
Generate all qubits between two given qubits coordinates (not inclusive).
- Parameters:
qubit1 (tuple[int, ...]:) – The first qubit (x1, y1, …).
qubit2 (tuple[int, ...]:) – The second qubit (x2, y2, …).
- Returns:
A list of qubits between the two qubits.
- Return type:
list[tuple[int, …]]
- loom_rotated_surface_code.applicator.merge.find_merge_stabilizer_to_circuit_mappings(blocks, new_stabs_left, new_stabs_right, new_stabs_top, new_stabs_bottom, new_bulk_stabilizers, old_stabs_to_lengthen)[source]
Finds the mapping between the stabilizers in the new block and the associated syndrome circuits.
- Parameters:
blocks (tuple[RotatedSurfaceCode, RotatedSurfaceCode]) – Blocks to merge.
new_stabs_left (list[Stabilizer]) – New stabilizers that form a part of the left boundary of the new block. This is an empty list for horizontal merges.
new_stabs_right (list[Stabilizer]) – New stabilizers that form a part of the right boundary of the new block. This is an empty list for horizontal merges.
new_stabs_top (list[Stabilizer]) – New stabilizers that form a part of the top boundary of the new block. This is an empty list for vertical merges.
new_stabs_bottom (list[Stabilizer]) – New stabilizers that form a part of the bottom boundary of the new block. This is an empty list for vertical merges.
new_bulk_stabilizers (list[Stabilizer]) – New stabilizers that form a part of the bulk of the new block.
old_stabs_to_lengthen (list[Stabilizer]) – Old stabilizers that are gonna be replaced by new stabilizers.
- Returns:
New mapping of stabilizers to syndrome circuits for the block.
- Return type:
dict[str, str]
- loom_rotated_surface_code.applicator.merge.merge(interpretation_step, operation, same_timeslice, debug_mode)[source]
Merge two blocks specified in the Merge operation.
The algorithm is the following:
A.) DATA QUBITS
A.1) Find data qubits to be measured in between the two blocks, they will be merged into a single new block
B.) CIRCUIT
B.1) Create classical channels for all data qubit measurements
B.2) Create a measurement circuit for every measured data qubit
B.3) Append the measurement circuits to the InterpretationStep circuit. If needed, apply a basis change
C.) - STABILIZERS
C.1) Create the new 4-body stabilizers located between the two initial blocks
C.2) Create the new 2-body stabilizers located at the merged boundaries
C.3) Find the 2-body stabilizers which weight should be increased
C.4) Find the associated 4-body stabilizers
C.5) Create the new
stabilizer_to_circuitmappingC.6) Create a single set of stabilizers for the new block
C.7) Update
stabilizer_evolutionandstabilizer_updatesfor the stabilizers which have been increased in weight
D.) LOGICAL OPERATORS
D.1) Align the 2 initial operators with stabilizer products
D.2) Retrieve the cbits coming from the latest equivalent stabilizer measurements.
D.3) Create new logical operators using qubits to measure
D.4) Update
logical_x/z_evolutionD.5) Update
logical_x/z_updates
E.) NEW BLOCK AND NEW INTERPRETATION STEP
E.1) Create the new block
E.2) Update the block history
F.) SYNDROMES
F.1) Generate syndromes for newly created stabilizers
JOINT OBSERVABLES
- G.1) Obtain the cbits for joint observable and store them in the
interpretation_step
- Parameters:
interpretation_step (InterpretationStep) – Input interpretation step.
operation (Merge) – Descriptor of the merge operation to perform.
same_timeslice (bool) – Flag indicating whether the operation is part of the same timestep as the previous operation.
debug_mode (bool) – Flag indicating whether the interpretation should be done in debug mode. Activating debug mode will enable commutation validation for Block.
- Returns:
Modified interpretation step after the merge operation.
- Return type:
- loom_rotated_surface_code.applicator.merge.merge_consistency_check(interpretation_step, operation)[source]
Check if the blocks are compatible for merging. Also re-orders the blocks so that block1 is the left or top block and block2 is the right or bottom block. This is required for the rest of the workflow to function properly.
- Parameters:
interpretation_step (InterpretationStep) – InterpretationStep containing the blocks to merge.
operation (Merge) – Descriptor of the merge operation to perform.
- Returns:
The blocks to merge, ordered so that block1 is the left or top block and block2 is the right or bottom block.
- Return type:
tuple[RotatedSurfaceCode, RotatedSurfaceCode]
- Raises:
ValueError – If the blocks are not compatible for merging. The blocks are compatible if: (1) They do not overlap (this should already be enforced). (2) The blocks’ upper left corner qubits are aligned (either horizontally or vertically). (3) The blocks have the same size in the direction normal to the merge. (4) The boundaries to be merged are of the same type. (5) The alternate pattern of stabilizers is preserved. I.e. the blocks have the same upper left 4-body stabilizer if the distance is even, different stabilizer if the distance is odd. (6) There needs to be at least one row/column of data qubits between the two blocks. (7) The blocks have a single logical operator. Also raises a ValueError if the orientation specified in the operation does not match the default orientation.
- loom_rotated_surface_code.applicator.merge.merge_logical_operators(interpretation_step, blocks, qubits_to_reset, merge_is_horizontal)[source]
Generate the new logical operators from the two blocks to merge. Note that they will be pushed to the upper left corner of the new block, similarly to the default choice of logical operators. This function also retrieves the lates measurements of the equivalent stabilizers and returns them.
- Parameters:
interpretation_step (InterpretationStep) – Interpretation step containing the blocks to merge.
blocks (tuple[RotatedSurfaceCode, RotatedSurfaceCode]) – Initial blocks to merge. By convention, the first block must be the one on the left or top. The second block must be the one on the right or bottom respectively.
qubits_to_reset (tuple[tuple[int, ...]]) – Qubits to measure between the two blocks.
merge_is_horizontal (bool) – Whether the merge is horizontal or vertical.
- Return type:
tuple[InterpretationStep,PauliOperator,tuple[Union[tuple[str,int],Literal[1,0]],...],PauliOperator,tuple[Union[tuple[str,int],Literal[1,0]],...]]- Returns:
tuple[ – InterpretationStep, PauliOperator, tuple[Cbit, …], PauliOperator, tuple[Cbit, …]
] – The updated interpretation step, the new logical X operator, the measurements coming from equivalent X stabilizers, the new logical Z operator and the measurements coming from equivalent Z stabilizers.
- loom_rotated_surface_code.applicator.merge.merge_stabilizers(blocks, merge_is_horizontal)[source]
Merge the two initial blocks stabilizers into a single lists of stabilizers, the list of old stabilizers that are gonna be replaced and the new stabilizers that will replace them.
- Parameters:
blocks (tuple[RotatedSurfaceCode, RotatedSurfaceCode]) – Blocks to merge. By construction blocks[0] should be the left or top block and blocks[1] should be the right or bottom block.
merge_is_horizontal (bool) – True if the merge is horizontal, False if the merge is vertical.
- Returns:
List of stabilizers forming the new block, list of old stabilizers to be replaced, list of new stabilizers which will replace them and map from stabilizer to the syndrome circuits.
- Return type:
tuple[list[Stabilizer], list[Stabilizer], list[Stabilizer], dict[str, str]]