logo

Expression of type Qcircuit

from the theory of proveit.physics.quantum.QPE

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 ExprRange, Variable, VertExprArray, t
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
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 = Add(t, one)
sub_expr3 = Add(t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _psi_t_ket, part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]))
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 + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \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
4ExprTuple8, 9
5ExprTuple10, 11
6ExprRangelambda_map: 12
start_index: 64
end_index: 65
7ExprRangelambda_map: 13
start_index: 64
end_index: 66
8ExprRangelambda_map: 14
start_index: 64
end_index: 65
9ExprRangelambda_map: 14
start_index: 54
end_index: 55
10ExprRangelambda_map: 15
start_index: 64
end_index: 65
11ExprRangelambda_map: 16
start_index: 64
end_index: 66
12Lambdaparameter: 53
body: 17
13Lambdaparameter: 53
body: 18
14Lambdaparameter: 53
body: 19
15Lambdaparameter: 53
body: 20
16Lambdaparameter: 53
body: 22
17Operationoperator: 39
operands: 23
18Operationoperator: 27
operands: 24
19Operationoperator: 27
operands: 25
20Operationoperator: 27
operands: 26
21ExprTuple53
22Operationoperator: 27
operands: 28
23NamedExprsstate: 29
24NamedExprselement: 30
targets: 36
25NamedExprselement: 31
targets: 32
26NamedExprselement: 33
targets: 34
27Literal
28NamedExprselement: 35
targets: 36
29Operationoperator: 37
operand: 49
30Operationoperator: 39
operands: 46
31Operationoperator: 40
operands: 41
32Operationoperator: 47
operands: 42
33Operationoperator: 45
operands: 43
34Operationoperator: 47
operands: 44
35Operationoperator: 45
operands: 46
36Operationoperator: 47
operands: 48
37Literal
38ExprTuple49
39Literal
40Literal
41NamedExprsoperation: 50
part: 53
42ExprTuple64, 55
43NamedExprsstate: 51
part: 53
44ExprTuple64, 65
45Literal
46NamedExprsstate: 52
part: 53
47Literal
48ExprTuple54, 55
49Literal
50Operationoperator: 56
operands: 57
51Operationoperator: 58
operand: 65
52Literal
53Variable
54Operationoperator: 61
operands: 60
55Operationoperator: 61
operands: 62
56Literal
57ExprTuple63, 65
58Literal
59ExprTuple65
60ExprTuple65, 64
61Literal
62ExprTuple65, 66
63Literal
64Literal
65Variable
66Literal