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, Mult, one
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, 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 = QPE(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 = var_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, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mult(two_pow_t, phase), t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_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}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{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, 6
3ExprTuple7, 8
4ExprTuple9, 10
5ExprTuple11, 12
6ExprTuple13, 14
7ExprRangelambda_map: 15
start_index: 77
end_index: 86
8ExprRangelambda_map: 16
start_index: 77
end_index: 78
9ExprRangelambda_map: 17
start_index: 77
end_index: 86
10ExprRangelambda_map: 17
start_index: 66
end_index: 67
11ExprRangelambda_map: 18
start_index: 77
end_index: 86
12ExprRangelambda_map: 19
start_index: 77
end_index: 78
13ExprRangelambda_map: 20
start_index: 77
end_index: 86
14ExprRangelambda_map: 21
start_index: 77
end_index: 78
15Lambdaparameter: 65
body: 22
16Lambdaparameter: 65
body: 23
17Lambdaparameter: 65
body: 24
18Lambdaparameter: 65
body: 25
19Lambdaparameter: 65
body: 26
20Lambdaparameter: 65
body: 27
21Lambdaparameter: 65
body: 29
22Operationoperator: 51
operands: 30
23Operationoperator: 37
operands: 31
24Operationoperator: 37
operands: 32
25Operationoperator: 33
operands: 34
26Operationoperator: 52
operands: 35
27Operationoperator: 37
operands: 36
28ExprTuple65
29Operationoperator: 37
operands: 38
30NamedExprsstate: 39
31NamedExprselement: 40
targets: 48
32NamedExprselement: 41
targets: 42
33Literal
34NamedExprsbasis: 43
35NamedExprsoperation: 44
36NamedExprselement: 45
targets: 46
37Literal
38NamedExprselement: 47
targets: 48
39Operationoperator: 49
operand: 61
40Operationoperator: 51
operands: 58
41Operationoperator: 52
operands: 53
42Operationoperator: 59
operands: 54
43Literal
44Literal
45Operationoperator: 57
operands: 55
46Operationoperator: 59
operands: 56
47Operationoperator: 57
operands: 58
48Operationoperator: 59
operands: 60
49Literal
50ExprTuple61
51Literal
52Literal
53NamedExprsoperation: 62
part: 65
54ExprTuple77, 67
55NamedExprsstate: 63
part: 65
56ExprTuple77, 86
57Literal
58NamedExprsstate: 64
part: 65
59Literal
60ExprTuple66, 67
61Literal
62Operationoperator: 68
operands: 69
63Operationoperator: 70
operands: 71
64Variable
65Variable
66Operationoperator: 73
operands: 72
67Operationoperator: 73
operands: 74
68Literal
69ExprTuple75, 86
70Literal
71ExprTuple76, 86
72ExprTuple86, 77
73Literal
74ExprTuple86, 78
75Variable
76Operationoperator: 79
operands: 80
77Literal
78Variable
79Literal
80ExprTuple81, 82
81Operationoperator: 83
operands: 84
82Variable
83Literal
84ExprTuple85, 86
85Literal
86Variable