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
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _ket_u, _psi__t_ket, _s, _t
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 = Interval(one, _t)
sub_expr3 = Interval(Add(_t, one), Add(_t, _s))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _psi__t_ket, part = sub_expr1), targets = sub_expr2), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr3), one, _s)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr2), one, _t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr3), 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 \psi_{t} \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \rangle} \\
\qin{\lvert u \rangle} & { /^{s} } \qw & \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: 63
end_index: 64
7ExprRangelambda_map: 13
start_index: 63
end_index: 65
8ExprRangelambda_map: 14
start_index: 63
end_index: 64
9ExprRangelambda_map: 15
start_index: 63
end_index: 65
10ExprRangelambda_map: 16
start_index: 63
end_index: 64
11ExprRangelambda_map: 17
start_index: 63
end_index: 65
12Lambdaparameter: 54
body: 18
13Lambdaparameter: 54
body: 19
14Lambdaparameter: 54
body: 20
15Lambdaparameter: 54
body: 21
16Lambdaparameter: 54
body: 22
17Lambdaparameter: 54
body: 24
18Operationoperator: 30
operands: 25
19Operationoperator: 30
operands: 26
20Operationoperator: 30
operands: 27
21Operationoperator: 42
operands: 28
22Operationoperator: 30
operands: 29
23ExprTuple54
24Operationoperator: 30
operands: 31
25NamedExprselement: 32
targets: 37
26NamedExprselement: 33
targets: 39
27NamedExprselement: 34
targets: 37
28NamedExprsoperation: 35
29NamedExprselement: 36
targets: 37
30Literal
31NamedExprselement: 38
targets: 39
32Operationoperator: 41
operands: 40
33Operationoperator: 41
operands: 47
34Operationoperator: 42
operands: 43
35Literal
36Operationoperator: 46
operands: 44
37Operationoperator: 48
operands: 45
38Operationoperator: 46
operands: 47
39Operationoperator: 48
operands: 49
40NamedExprsstate: 50
part: 54
41Literal
42Literal
43NamedExprsoperation: 51
part: 54
44NamedExprsstate: 52
part: 54
45ExprTuple63, 64
46Literal
47NamedExprsstate: 53
part: 54
48Literal
49ExprTuple55, 56
50Operationoperator: 57
operand: 64
51Operationoperator: 58
operand: 64
52Literal
53Literal
54Variable
55Operationoperator: 61
operands: 60
56Operationoperator: 61
operands: 62
57Literal
58Literal
59ExprTuple64
60ExprTuple64, 63
61Literal
62ExprTuple64, 65
63Literal
64Literal
65Literal