logo

Expression of type Circuit

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 ExprArray
from proveit.logic import Set
from proveit.numbers import one, two
from proveit.physics.quantum import CONTROL, Hgate, Input, Ket, Output, ket0
from proveit.physics.quantum.QPE import U_, psi_1, u_
from proveit.physics.quantum.circuit import Circuit, IdentityOp, MultiQubitGate
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Set(one, two)
sub_expr2 = Ket(u_)
expr = Circuit(ExprArray([Input(ket0), Hgate, MultiQubitGate(CONTROL, sub_expr1), Output(Ket(psi_1))], [Input(sub_expr2), IdentityOp(), MultiQubitGate(U_, sub_expr1), Output(sub_expr2)]))
Out[2]:
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(expr.latex())
\hspace{2em} \Qcircuit@C=1em @R=.7em{
& \lstick{\lvert 0 \rangle} & \gate{H} & \control \qw \qwx[1] & \rstick{\lvert \psi_{1} \rangle} \qw   \\ 
  & \lstick{\lvert u \rangle} & \qw & \gate{U} & \rstick{\lvert u \rangle} \qw 
} \hspace{2em}
In [5]:
expr.style_options()
Out[5]:
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
orientationto be read from left to right then top to bottom ('horizontal') or to be read top to bottom then left to right ('vertical')horizontalhorizontalwith_orientation
In [6]:
# display the expression information
expr.expr_info()
Out[6]:
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3None
3ExprTuple4, 5None
4ExprTuple6, 7, 8, 9
5ExprTuple10, 11, 12, 13
6Operationoperator: 19
operand: 24
7Operationoperator: 15
operand: 25
8Operationoperator: 20
operands: 17
9Operationoperator: 22
operand: 27
10Operationoperator: 19
operand: 30
11Literal
12Operationoperator: 20
operands: 21
13Operationoperator: 22
operand: 30
14ExprTuple24
15Literal
16ExprTuple25
17ExprTuple26, 29
18ExprTuple27
19Literal
20Literal
21ExprTuple28, 29
22Literal
23ExprTuple30
24Operationoperator: 35
operand: 37
25Literal
26Literal
27Operationoperator: 35
operand: 38
28Literal
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operand: 40
31ExprTuple37
32ExprTuple38
33Literal
34ExprTuple44, 39
35Literal
36ExprTuple40
37Literal
38Operationoperator: 41
operands: 42
39Literal
40Literal
41Literal
42ExprTuple43, 44
43Literal
44Literal