circuit#
The category of classical-quantum circuits with digits and qudits as objects.
Summary#
A circuit object is an information unit with some dimension |
|
A digit is a classical unit of information. |
|
A qudit is a quantum unit of information, i.e. a quantum digit. |
|
A circuit type is a frobenius type with |
|
A circuit is a tensor diagram with bits and qubits as |
|
A circuit box is a tensor box in a circuit diagram. |
|
Sums of circuits. |
|
Implements swaps of circuit wires. |
|
|
Functions
Turns an index into a bitstring of a given length. |
|
Turns a bitstring into an index. |
Examples
>>> from discopy.quantum.gates import (
... Ket, CX, H, X, Rz, sqrt, Controlled, Measure, Discard)
>>> circuit = Ket(0, 0) >> CX >> Controlled(Rz(0.25)) >> Measure() @ Discard()
>>> circuit.draw(
... figsize=(3, 6),
... path='docs/_static/quantum/circuit-example.png')
>>> from discopy.grammar import pregroup
>>> s, n = pregroup.Ty('s'), pregroup.Ty('n')
>>> Alice = pregroup.Word('Alice', n)
>>> loves = pregroup.Word('loves', n.r @ s @ n.l)
>>> Bob = pregroup.Word('Bob', n)
>>> grammar = pregroup.Cup(n, n.r) @ s @ pregroup.Cup(n.l, n)
>>> sentence = grammar << Alice @ loves @ Bob
>>> ob = {s: Ty(), n: qubit}
>>> ar = {Alice: Ket(0),
... loves: CX << sqrt(2) @ H @ X << Ket(0, 0),
... Bob: Ket(1)}
>>> F = pregroup.Functor(ob, ar, cod=Category(Ty, Circuit))
>>> assert abs(F(sentence).eval().array) ** 2
>>> from discopy.drawing import Equation
>>> Equation(
... sentence, F(sentence).foliation(), symbol='$\\mapsto$').draw(
... path='docs/_static/quantum/functor-example.png')