Bitwise Operations#
from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register
from qualtran import QBit, QInt, QUInt, QAny
from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma
from typing import *
import numpy as np
import sympy
import cirq
Xor
#
Xor the value of one register into another via CNOTs.
Maps basis states \(|x, y\rangle\) to \(|x, y \oplus x\rangle\).
When both registers are in computational basis and the destination is 0, effectively copies the value of the source into the destination.
Parameters#
dtype
: Data type of the input registersx
andy
.
Registers#
x
: The source register.y
: The target register.
from qualtran.bloqs.arithmetic import Xor
Example Instances#
xor = Xor(QAny(4))
xor_symb = Xor(QAny(sympy.Symbol("n")))
Graphical Signature#
from qualtran.drawing import show_bloqs
show_bloqs([xor, xor_symb],
['`xor`', '`xor_symb`'])
Call Graph#
from qualtran.resource_counting.generalizers import ignore_split_join
xor_g, xor_sigma = xor.call_graph(max_depth=1, generalizer=ignore_split_join)
show_call_graph(xor_g)
show_counts_sigma(xor_sigma)
Counts totals:
CNOT
: 4
BitwiseNot
#
Flips every bit of the input register.
Parameters#
dtype
: Data type of the input registerx
.
Registers#
x
: A quantum register of typeself.dtype
.
from qualtran.bloqs.arithmetic import BitwiseNot
Example Instances#
bitwise_not = BitwiseNot(QUInt(4))
n = sympy.Symbol("n")
bitwise_not_symb = BitwiseNot(QUInt(n))
Graphical Signature#
from qualtran.drawing import show_bloqs
show_bloqs([bitwise_not, bitwise_not_symb],
['`bitwise_not`', '`bitwise_not_symb`'])
Call Graph#
from qualtran.resource_counting.generalizers import ignore_split_join
bitwise_not_g, bitwise_not_sigma = bitwise_not.call_graph(max_depth=1, generalizer=ignore_split_join)
show_call_graph(bitwise_not_g)
show_counts_sigma(bitwise_not_sigma)
Counts totals:
XGate⨂4
: 1