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 Interval, one
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _psi__t_ket, _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)
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 = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t)]))
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}
} \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
4ExprTuple7
5ExprTuple8
6ExprRangelambda_map: 9
start_index: 36
end_index: 40
7ExprRangelambda_map: 10
start_index: 36
end_index: 40
8ExprRangelambda_map: 11
start_index: 36
end_index: 40
9Lambdaparameter: 35
body: 12
10Lambdaparameter: 35
body: 13
11Lambdaparameter: 35
body: 15
12Operationoperator: 18
operands: 16
13Operationoperator: 18
operands: 17
14ExprTuple35
15Operationoperator: 18
operands: 19
16NamedExprselement: 20
targets: 23
17NamedExprselement: 21
targets: 23
18Literal
19NamedExprselement: 22
targets: 23
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operands: 27
22Operationoperator: 28
operands: 29
23Operationoperator: 30
operands: 31
24Literal
25NamedExprsstate: 32
part: 35
26Literal
27NamedExprsoperation: 33
part: 35
28Literal
29NamedExprsstate: 34
part: 35
30Literal
31ExprTuple36, 40
32Operationoperator: 37
operand: 40
33Operationoperator: 38
operand: 40
34Literal
35Variable
36Literal
37Literal
38Literal
39ExprTuple40
40Literal