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.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, Neg, one, two, zero
from proveit.physics.quantum.QPE import _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import MultiQubitElem, Output, 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 = TensorProd(_psi_t_ket, _ket_u)
sub_expr4 = Interval(one, sub_expr2)
expr = Qcircuit(vert_expr_array = VertExprArray([MultiQubitElem(element = Output(state = sub_expr3, part = one), targets = sub_expr4), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = Add(sub_expr1, t)), targets = sub_expr4), Add(Neg(t), two), zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = sub_expr1), targets = sub_expr4), Add(t, one), sub_expr2).with_wrapping_at(2,6)]))
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{
& \multiqout{2}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \qout{\vdots} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}}
} \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
operand: 3
1Literal
2ExprTuple3
3ExprTuple4, 5, 6
4Operationoperator: 23
operands: 7
5ExprRangelambda_map: 8
start_index: 9
end_index: 10
6ExprRangelambda_map: 11
start_index: 12
end_index: 37
7NamedExprselement: 13
targets: 28
8Lambdaparameter: 43
body: 14
9Operationoperator: 41
operands: 15
10Literal
11Lambdaparameter: 43
body: 17
12Operationoperator: 41
operands: 18
13Operationoperator: 30
operands: 19
14Operationoperator: 23
operands: 20
15ExprTuple21, 22
16ExprTuple43
17Operationoperator: 23
operands: 24
18ExprTuple49, 36
19NamedExprsstate: 35
part: 36
20NamedExprselement: 25
targets: 28
21Operationoperator: 26
operand: 49
22Literal
23Literal
24NamedExprselement: 27
targets: 28
25Operationoperator: 30
operands: 29
26Literal
27Operationoperator: 30
operands: 31
28Operationoperator: 32
operands: 33
29NamedExprsstate: 35
part: 34
30Literal
31NamedExprsstate: 35
part: 43
32Literal
33ExprTuple36, 37
34Operationoperator: 41
operands: 38
35Operationoperator: 39
operands: 40
36Literal
37Operationoperator: 41
operands: 42
38ExprTuple43, 49
39Literal
40ExprTuple44, 45
41Literal
42ExprTuple49, 46
43Variable
44Operationoperator: 47
operand: 49
45Literal
46Literal
47Literal
48ExprTuple49
49Variable