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 A, ExprRange, IndexedVar, Variable, VertExprArray, k, l
from proveit.numbers import Interval, one
from proveit.physics.quantum import var_ket_u, var_ket_v
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 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Interval(one, l)
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr3), one, l)], ExprRange(sub_expr2, [ExprRange(sub_expr1, IndexedVar(A, [sub_expr2, sub_expr1]), one, l)], one, k), [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_v, part = sub_expr1), targets = sub_expr3), one, l)]))
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{
\multiqin{3}{\lvert u \rangle} & \gate{A_{1, 1}} \qwx[1] & \gate{A_{2, 1}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 1}} \qwx[1] & \multiqout{3}{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, 2}} \qwx[1] & \gate{A_{2, 2}} \qwx[1] & \gate{\cdots} \qwx[1] & \gate{A_{k, 2}} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} \qwx[1] & \ghostqout{\lvert v \rangle} \\
\ghostqin{\lvert u \rangle} & \gate{A_{1, l}} & \gate{A_{2, l}} & \gate{\cdots} & \gate{A_{k, l}} & \ghostqout{\lvert v \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
4ExprRangelambda_map: 7
start_index: 38
end_index: 8
5ExprTuple9
6ExprRangelambda_map: 10
start_index: 38
end_index: 39
7Lambdaparameter: 35
body: 12
8Variable
9ExprRangelambda_map: 13
start_index: 38
end_index: 39
10Lambdaparameter: 37
body: 14
11ExprTuple35
12ExprTuple15
13Lambdaparameter: 37
body: 16
14Operationoperator: 19
operands: 17
15ExprRangelambda_map: 18
start_index: 38
end_index: 39
16Operationoperator: 19
operands: 20
17NamedExprselement: 21
targets: 25
18Lambdaparameter: 37
body: 23
19Literal
20NamedExprselement: 24
targets: 25
21Operationoperator: 26
operands: 27
22ExprTuple37
23IndexedVarvariable: 28
indices: 29
24Operationoperator: 30
operands: 31
25Operationoperator: 32
operands: 33
26Literal
27NamedExprsstate: 34
part: 37
28Variable
29ExprTuple35, 37
30Literal
31NamedExprsstate: 36
part: 37
32Literal
33ExprTuple38, 39
34Variable
35Variable
36Variable
37Variable
38Literal
39Variable