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 registers x and y.

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)
../../_images/fc74c59fedf966aa56619a59e881b393aafde9de4c5bb9dbd074b2d3a8548981.svg

Counts totals:

  • CNOT: 4

BitwiseNot#

Flips every bit of the input register.

Parameters#

  • dtype: Data type of the input register x.

Registers#

  • x: A quantum register of type self.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)
../../_images/d721d015a98bcd7d1d761f12a430fb5e125409abe4f07e3ee228fdfb481f7906.svg

Counts totals:

  • XGate⨂4: 1