logo

Expression of type Qcircuit

from the theory of proveit.physics.quantum.circuits

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, a, b, k
from proveit.core_expr_types import U_1_to_m
from proveit.numbers import Interval, one
from proveit.physics.quantum.circuits import 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, k)
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = a, part = sub_expr1), targets = sub_expr2), one, k)], U_1_to_m, [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = b, part = sub_expr1), targets = sub_expr2), one, k)]))
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{a} & \gate{\begin{array}{c} \uparrow \\U_{1} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\U_{2} \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\\cdots \\ \downarrow\end{array}} & \gate{\begin{array}{c} \uparrow \\U_{m} \\ \downarrow\end{array}} & \qout{b}
} \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
4ExprRangelambda_map: 7
start_index: 32
end_index: 8
5ExprTuple9
6ExprRangelambda_map: 10
start_index: 32
end_index: 33
7Lambdaparameter: 31
body: 11
8Variable
9ExprRangelambda_map: 12
start_index: 32
end_index: 33
10Lambdaparameter: 31
body: 13
11IndexedVarvariable: 14
index: 31
12Lambdaparameter: 31
body: 16
13Operationoperator: 18
operands: 17
14Variable
15ExprTuple31
16Operationoperator: 18
operands: 19
17NamedExprselement: 20
targets: 22
18Literal
19NamedExprselement: 21
targets: 22
20Operationoperator: 23
operands: 24
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operands: 28
23Literal
24NamedExprsstate: 29
part: 31
25Literal
26NamedExprsstate: 30
part: 31
27Literal
28ExprTuple32, 33
29Variable
30Variable
31Variable
32Literal
33Variable