logo

Expression of type Qcircuit

from the theory of proveit.physics.quantum.circuits

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import A, ExprRange, IndexedVar, Variable, VertExprArray, k, l, m
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I, var_ket_psi, var_ket_u, var_ket_v
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Interval(one, m)
sub_expr4 = Interval(Add(m, one), Add(m, l))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_psi, part = sub_expr1), targets = sub_expr3), one, m), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, l)], ExprRange(sub_expr2, [ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, m), ExprRange(sub_expr1, IndexedVar(A, [sub_expr2, sub_expr1]), one, l)], one, k), [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_psi, part = sub_expr1), targets = sub_expr3), one, m), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_v, part = sub_expr1), targets = sub_expr4), one, l)]))
expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & { /^{m} } \qw & { /^{m} } \qw & \gate{\cdots} & { /^{m} } \qw & \qout{\lvert \psi \rangle} \\
\multiqin{3}{\lvert u \rangle} & \gate{A_{1, 1}} \qwx[1] & \gate{A_{2, 1}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 1}} \qwx[1] & \multiqout{3}{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, 2}} \qwx[1] & \gate{A_{2, 2}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 2}} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, l}} & \gate{A_{2, l}} & \gate{\cdots} & \gate{A_{k, l}} & \ghostqout{\lvert v \rangle}
} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
spacingchange the spacing of a circuit using the format '@C=1em @R=.7em' where C is the column spacing and R is the row spacing@C=1em @R=.7em@C=1em @R=.7em
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4, 5
3ExprTuple6, 7
4ExprRangelambda_map: 8
start_index: 63
end_index: 9
5ExprTuple10, 11
6ExprRangelambda_map: 12
start_index: 63
end_index: 64
7ExprRangelambda_map: 13
start_index: 63
end_index: 65
8Lambdaparameter: 54
body: 15
9Variable
10ExprRangelambda_map: 16
start_index: 63
end_index: 64
11ExprRangelambda_map: 17
start_index: 63
end_index: 65
12Lambdaparameter: 57
body: 18
13Lambdaparameter: 57
body: 19
14ExprTuple54
15ExprTuple20, 21
16Lambdaparameter: 57
body: 22
17Lambdaparameter: 57
body: 23
18Operationoperator: 29
operands: 24
19Operationoperator: 29
operands: 25
20ExprRangelambda_map: 26
start_index: 63
end_index: 64
21ExprRangelambda_map: 27
start_index: 63
end_index: 65
22Operationoperator: 29
operands: 28
23Operationoperator: 29
operands: 30
24NamedExprselement: 31
targets: 37
25NamedExprselement: 32
targets: 39
26Lambdaparameter: 57
body: 33
27Lambdaparameter: 57
body: 35
28NamedExprselement: 36
targets: 37
29Literal
30NamedExprselement: 38
targets: 39
31Operationoperator: 40
operands: 46
32Operationoperator: 40
operands: 41
33Operationoperator: 42
operands: 43
34ExprTuple57
35IndexedVarvariable: 44
indices: 45
36Operationoperator: 48
operands: 46
37Operationoperator: 50
operands: 47
38Operationoperator: 48
operands: 49
39Operationoperator: 50
operands: 51
40Literal
41NamedExprsstate: 52
part: 57
42Literal
43NamedExprsoperation: 53
44Variable
45ExprTuple54, 57
46NamedExprsstate: 55
part: 57
47ExprTuple63, 64
48Literal
49NamedExprsstate: 56
part: 57
50Literal
51ExprTuple58, 59
52Variable
53Literal
54Variable
55Variable
56Variable
57Variable
58Operationoperator: 61
operands: 60
59Operationoperator: 61
operands: 62
60ExprTuple64, 63
61Literal
62ExprTuple64, 65
63Literal
64Variable
65Variable