Skip to main content
Functions:
NameDescription
binary_to_one_hotConversion of binary encoded value to one-hot encoding.
binary_to_unaryConversion of binary encoded value to unary encoding.
one_hot_to_unaryConversion of one-hot encoded value to unary encoding.
one_hot_to_binaryConversion of one-hot encoded value to binary encoding.
unary_to_one_hotConversion of unary encoded value to one-hot encoding.
unary_to_binaryConversion of unary encoded value to binary encoding.
inplace_binary_to_one_hotInplace conversion of binary encoded value to one-hot encoding.
inplace_one_hot_to_unaryInplace conversion of one-hot encoded value to unary encoding.
pad_zerosPad the input qvar with additional qubits at the end to reach the total_size.

binary_to_one_hot

binary_to_one_hot(
binary: Input[QNum],
one_hot: Output[QArray]
) -> None
Conversion of binary encoded value to one-hot encoding. The output one_hot variable is of size 2^n, where n is the number of bits in the binary representation. For example, the state |01>=|2> will be converted to |0010> (one-hot for 2). Parameters:
NameTypeDescriptionDefault
binaryInput[QNum]binary input variable to be converted to one-hot encoding.required
one_hotOutput[QArray]one-hot output array.required

binary_to_unary

binary_to_unary(
binary: Input[QNum],
unary: Output[QArray]
) -> None
Conversion of binary encoded value to unary encoding. The output unary variable is of size 2^n - 1, where n is the number of bits in the binary representation. For example, the state |01>=|2> will be converted to |110> (unary for 2). Parameters:
NameTypeDescriptionDefault
binaryInput[QNum]binary input variable to be converted to unary encoding.required
unaryOutput[QArray]unary output array.required

one_hot_to_unary

one_hot_to_unary(
one_hot: Input[QArray],
unary: Output[QArray]
) -> None
Conversion of one-hot encoded value to unary encoding. The output unary variable is smaller in 1 qubit than the input one_hot variable. For example, the state |0010> (one-hot for 2) will be converted to |110> (unary for 2). Parameters:
NameTypeDescriptionDefault
one_hotInput[QArray]one-hot input array to be converted to unary encoding.required
unaryOutput[QArray]unary output array.required

one_hot_to_binary

one_hot_to_binary(
one_hot: Input[QArray],
binary: Output[QNum[Literal[‘ceiling(log(one_hot.len, 2))’]]]
) -> None
Conversion of one-hot encoded value to binary encoding. The output binary variable is of size log2(one_hot.size) rounded up. For example, the state |0010> (one-hot for 2) will be converted to |01>=|2>. Parameters:
NameTypeDescriptionDefault
one_hotInput[QArray]one-hot input array to be converted to binary encoding.required
binaryOutput[QNum[Literal['ceiling(log(one_hot.len, 2))']]]binary output variable.required

unary_to_one_hot

unary_to_one_hot(
unary: Input[QArray],
one_hot: Output[QArray]
) -> None
Conversion of unary encoded value to one-hot encoding. The output one_hot variable is larger in 1 qubit than the input unary variable. For example, the state |110> (unary for 2) will be converted to |0010> (one-hot for 2). Parameters:
NameTypeDescriptionDefault
unaryInput[QArray]unary input array to be converted to one-hot encoding.required
one_hotOutput[QArray]one-hot output array.required

unary_to_binary

unary_to_binary(
unary: Input[QArray],
binary: Output[QNum]
) -> None
Conversion of unary encoded value to binary encoding. The output binary variable is of size log2(unary.size + 1) rounded up. For example, the state |110> (unary for 2) will be converted to |01>=|2>. Parameters:
NameTypeDescriptionDefault
unaryInput[QArray]unary input array to be converted to binary encoding.required
binaryOutput[QNum]binary output variable.required

inplace_binary_to_one_hot

inplace_binary_to_one_hot(
qvar: QArray
) -> None
Inplace conversion of binary encoded value to one-hot encoding. The implementation is based on https://quantumcomputing.stackexchange.com/questions/5526/garbage-free-reversible-binary-to-unary-decoder-construction. The input is assumed to be of size 2^n, where n is the number of bits in the binary representation. For example, the state |01000>=|2> will be converted to |00100> (one-hot for 2). Parameters:
NameTypeDescriptionDefault
qvarQArraybinary input array padded with 0’s to be converted to one-hot encoding.required

inplace_one_hot_to_unary

inplace_one_hot_to_unary(
qvar: QArray
) -> None
Inplace conversion of one-hot encoded value to unary encoding. The input is assumed to be of size n, where n is the number of bits in the one-hot representation. The remaining unary representation will at the higher n-1 bits, where the lsb is cleared to 0. For example, the state |0010> (one-hot for 2) will be converted to |0>``|110> (unary for 2). Parameters:
NameTypeDescriptionDefault
qvarQArrayone-hot input array to be converted to unary encoding.required

pad_zeros

pad_zeros(
total_size: int,
qvar: Input[QArray],
padded: Output[QArray]
) -> None
Pad the input qvar with additional qubits at the end to reach the total_size. Parameters:
NameTypeDescriptionDefault
total_sizeintThe desired total size after padding.required
qvarInput[QArray]The input quantum array to be padded.required
paddedOutput[QArray]The output quantum array after padding.required