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, Literal, Variable, VertExprArray, t
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, SubIndexed
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(Literal("t", theory = "proveit.physics.quantum.QPE"), one)
sub_expr3 = Add(Literal("t", theory = "proveit.physics.quantum.QPE"), Literal("s", theory = "proveit.physics.quantum.QPE"))
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE1(Literal("U", theory = "proveit.physics.quantum.QPE"), Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, sub_expr5, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = SubIndexed(Literal("psi", latex_format = r"\psi", theory = "proveit.physics.quantum.QPE"), [t]), part = sub_expr1), targets = Interval(one, Literal("t", theory = "proveit.physics.quantum.QPE"))), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))]))
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: 65
end_index: 66
7ExprRangelambda_map: 13
start_index: 65
end_index: 67
8ExprRangelambda_map: 14
start_index: 65
end_index: 66
9ExprRangelambda_map: 14
start_index: 54
end_index: 55
10ExprRangelambda_map: 15
start_index: 65
end_index: 66
11ExprRangelambda_map: 16
start_index: 65
end_index: 67
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
42ExprTuple65, 55
43NamedExprsstate: 51
part: 53
44ExprTuple65, 66
45Literal
46NamedExprsstate: 52
part: 53
47Literal
48ExprTuple54, 55
49Literal
50Operationoperator: 56
operands: 57
51Operationoperator: 58
operand: 64
52Literal
53Variable
54Operationoperator: 61
operands: 60
55Operationoperator: 61
operands: 62
56Literal
57ExprTuple63, 66
58Literal
59ExprTuple64
60ExprTuple66, 65
61Literal
62ExprTuple66, 67
63Literal
64Variable
65Literal
66Literal
67Literal