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, U, Variable, VertExprArray, m
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.logic import Set
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import CONTROL, ket0, ket1, ket_plus, var_ket_u, varphi
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 = Add(m, one)
sub_expr3 = Interval(two, Add(m, two))
expr = Qcircuit(vert_expr_array = VertExprArray([Input(state = ket_plus), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr3), one, sub_expr2)], [MultiQubitElem(element = CONTROL, targets = Set(two)), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = U, part = sub_expr1), targets = sub_expr3), one, sub_expr2)], [Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, varphi)), ket1)))), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr3), 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{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U} & \qout{\lvert u \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, 7
4ExprTuple8, 9
5ExprTuple10, 11
6Operationoperator: 43
operands: 12
7ExprRangelambda_map: 13
start_index: 79
end_index: 18
8Operationoperator: 34
operands: 14
9ExprRangelambda_map: 15
start_index: 79
end_index: 18
10Operationoperator: 49
operands: 16
11ExprRangelambda_map: 17
start_index: 79
end_index: 18
12NamedExprsstate: 19
13Lambdaparameter: 58
body: 20
14NamedExprselement: 21
targets: 22
15Lambdaparameter: 58
body: 23
16NamedExprsstate: 24
17Lambdaparameter: 58
body: 26
18Operationoperator: 64
operands: 27
19Operationoperator: 75
operand: 36
20Operationoperator: 34
operands: 29
21Literal
22Operationoperator: 30
operand: 82
23Operationoperator: 34
operands: 32
24Operationoperator: 62
operands: 33
25ExprTuple58
26Operationoperator: 34
operands: 35
27ExprTuple70, 79
28ExprTuple36
29NamedExprselement: 37
targets: 42
30Literal
31ExprTuple82
32NamedExprselement: 38
targets: 42
33ExprTuple39, 40
34Literal
35NamedExprselement: 41
targets: 42
36Literal
37Operationoperator: 43
operands: 50
38Operationoperator: 44
operands: 45
39Operationoperator: 71
operands: 46
40Operationoperator: 47
operands: 48
41Operationoperator: 49
operands: 50
42Operationoperator: 51
operands: 52
43Literal
44Literal
45NamedExprsoperation: 53
part: 58
46ExprTuple79, 54
47Literal
48ExprTuple55, 56
49Literal
50NamedExprsstate: 57
part: 58
51Literal
52ExprTuple82, 59
53Variable
54Operationoperator: 73
operands: 60
55Operationoperator: 75
operand: 67
56Operationoperator: 62
operands: 63
57Variable
58Variable
59Operationoperator: 64
operands: 65
60ExprTuple82, 66
61ExprTuple67
62Literal
63ExprTuple68, 69
64Literal
65ExprTuple70, 82
66Operationoperator: 71
operands: 72
67Literal
68Operationoperator: 73
operands: 74
69Operationoperator: 75
operand: 79
70Variable
71Literal
72ExprTuple79, 82
73Literal
74ExprTuple77, 78
75Literal
76ExprTuple79
77Literal
78Operationoperator: 80
operands: 81
79Literal
80Literal
81ExprTuple82, 83, 84, 85
82Literal
83Literal
84Literal
85Variable