swap_circuit_utils
swap_circuit_utils ¶
big_reg_to_list ¶
Converts a big input Qubits register into a list of smaller Qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
big_reg
|
Qubits
|
Big register given as input. |
required |
size
|
int
|
Number of qubits on sub-registers. |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of qubit registers of size |
bit_swap ¶
Swap the p1'th and the p2'th bits of an input bitstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bitstring
|
int
|
Bitstring given as an integer. |
required |
p1
|
int
|
Position of the first bit sequence. |
required |
p2
|
int
|
Position of the second bit sequence. |
required |
num_bits
|
int
|
How may bits to swap. |
required |
Returns:
| Type | Description |
|---|---|
int
|
A new bitstring with bits swapped. |
reg_swap ¶
Swap the p1'th and the p2'th registers of an input bitstring.
This function performs the same bitwise logic as bit_swap, but here
we interpret the position arguments as indexes for an entire register
made up of some number of bits rather than as indexes to the position
of particular bits. It's really just a convenience to not have to
constantly consider shifting indices by num_bits amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bitstring
|
int
|
Bitstring given as an integer. |
required |
p1
|
int
|
Position of the first register. |
required |
p2
|
int
|
Position of the second register. |
required |
num_bits
|
int
|
Number of bits per register. |
required |
Returns:
| Type | Description |
|---|---|
int
|
A new bitstring with bits swapped. |
reshuffled_bitmask ¶
Calculate the reshuffled bitmask resulting from permuting bits.
This function serves as a bookeeping tool to keep track of the resulting reshuffled bitmask on the entirety of a register that has undergone a swap network. Given an index value as input, the swap network assumed by this function moves the indexed register to the topmost (least significant in little endian notation) position in the reshuffled bitmask.
The resulting bitmask on the rest of the input bits is generally ignored and
not made use of. In fact, there are arbitrarily many permutations one could
opt for. This function assumes a particular reshuffling permutation. The
reshuffling done here follows the same pattern performed by our SwapUp
Qubricks. Using this function, you can now uniquely associate an input index
with an output value written on all the qubits in the target register
rather than only the top reg_size many qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_val
|
int
|
Address value we input which then results in a reshuffling of the input bitmask. |
required |
bitmask
|
int
|
Integer value encoded on some bits prior to reshuffling. |
required |
num_regs
|
int
|
Number of registers we are permuting. |
required |
reg_size
|
int
|
The number of bits per register. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The reshuffled bitmask, given as an integer. |