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
from proveit.numbers import Add, Interval, one
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(Literal("t", theory = "proveit.physics.quantum.QPE"), Literal("s", theory = "proveit.physics.quantum.QPE"))
sub_expr3 = 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_expr2))
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr3, Add(Literal("t", theory = "proveit.physics.quantum.QPE"), one), sub_expr2)]))
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)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{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
operand: 3
1Literal
2ExprTuple3
3ExprTuple4, 5
4ExprRangelambda_map: 6
start_index: 21
end_index: 28
5ExprRangelambda_map: 6
start_index: 7
end_index: 22
6Lambdaparameter: 20
body: 9
7Operationoperator: 25
operands: 10
8ExprTuple20
9Operationoperator: 11
operands: 12
10ExprTuple28, 21
11Literal
12NamedExprselement: 13
targets: 14
13Operationoperator: 15
operands: 16
14Operationoperator: 17
operands: 18
15Literal
16NamedExprsoperation: 19
part: 20
17Literal
18ExprTuple21, 22
19Operationoperator: 23
operands: 24
20Variable
21Literal
22Operationoperator: 25
operands: 26
23Literal
24ExprTuple27, 28
25Literal
26ExprTuple28, 29
27Literal
28Literal
29Literal