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, U, Variable, VertExprArray, s, t
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 QPE1
from proveit.physics.quantum.circuits import Gate, MultiQubitElem, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, s)
sub_expr3 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, t), ExprRange(sub_expr1, sub_expr3, Add(t, one), sub_expr2)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), 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{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & \gate{{\mathrm {FT}}^{\dag}_{t}} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw & { /^{s} } \qw
} \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
3ExprTuple5, 6
4ExprTuple7, 8
5ExprRangelambda_map: 9
start_index: 37
end_index: 46
6ExprRangelambda_map: 9
start_index: 10
end_index: 34
7ExprRangelambda_map: 11
start_index: 37
end_index: 46
8ExprRangelambda_map: 12
start_index: 37
end_index: 45
9Lambdaparameter: 36
body: 13
10Operationoperator: 40
operands: 14
11Lambdaparameter: 36
body: 15
12Lambdaparameter: 36
body: 17
13Operationoperator: 19
operands: 18
14ExprTuple46, 37
15Operationoperator: 19
operands: 20
16ExprTuple36
17Operationoperator: 29
operands: 21
18NamedExprselement: 22
targets: 23
19Literal
20NamedExprselement: 24
targets: 25
21NamedExprsoperation: 26
22Operationoperator: 29
operands: 27
23Operationoperator: 31
operands: 28
24Operationoperator: 29
operands: 30
25Operationoperator: 31
operands: 32
26Literal
27NamedExprsoperation: 33
part: 36
28ExprTuple37, 34
29Literal
30NamedExprsoperation: 35
part: 36
31Literal
32ExprTuple37, 46
33Operationoperator: 38
operands: 39
34Operationoperator: 40
operands: 41
35Operationoperator: 42
operand: 46
36Variable
37Literal
38Literal
39ExprTuple44, 46
40Literal
41ExprTuple46, 45
42Literal
43ExprTuple46
44Variable
45Variable
46Variable