Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/notebooks/intro/writing_tools.py
3855 views
1
# # These tools are for creating matrices with the annotation tags added automatically
2
3
def example_matrix_tooltips():
4
# For generating the latex for t_{in \rightarrow out} matrix
5
s = ''
6
for row in range(4):
7
for column in range(4):
8
c, r = f'{column:02b}', f'{row:02b}'
9
s += f'\\class{{t_amp_{c}_{r}}}{{t_{{{c}\\to {r}}}}} & '
10
s = s[:-2]
11
s += '\\\\\n'
12
print(s)
13
14
15
def example_matrix_metadata():
16
# For generating the metadata for t_{in \rightarrow out} matrix
17
msg = """
18
"t_amp_{c}_{r}": {{
19
"meaning": "This is the amplitude of this operation transforming the state <code>{c}</code> to <code>{r}</code>."
20
}},
21
"""
22
s = ''
23
for row in range(4):
24
for column in range(4):
25
c, r = f'{column:02b}', f'{row:02b}'
26
s += msg.format(c=c, r=r)
27
s = s[:-2]
28
print(s)
29
30
31
def matrix_tooltips(gate):
32
# For making latex w/ tooltips from a matrix
33
s = ''
34
size = len(gate[0])
35
for row in range(size):
36
for column in range(size):
37
c, r = f'{column:02b}', f'{row:02b}'
38
s += f'\\class{{t_amp_{c}_{r}}}{{{gate[row][column]}}} & '
39
s = s[:-2]
40
s += '\\\\\n'
41
print(s)
42
43