Path: blob/main/notebooks/intro/writing_tools.py
3855 views
# # These tools are for creating matrices with the annotation tags added automatically12def example_matrix_tooltips():3# For generating the latex for t_{in \rightarrow out} matrix4s = ''5for row in range(4):6for column in range(4):7c, r = f'{column:02b}', f'{row:02b}'8s += f'\\class{{t_amp_{c}_{r}}}{{t_{{{c}\\to {r}}}}} & '9s = s[:-2]10s += '\\\\\n'11print(s)121314def example_matrix_metadata():15# For generating the metadata for t_{in \rightarrow out} matrix16msg = """17"t_amp_{c}_{r}": {{18"meaning": "This is the amplitude of this operation transforming the state <code>{c}</code> to <code>{r}</code>."19}},20"""21s = ''22for row in range(4):23for column in range(4):24c, r = f'{column:02b}', f'{row:02b}'25s += msg.format(c=c, r=r)26s = s[:-2]27print(s)282930def matrix_tooltips(gate):31# For making latex w/ tooltips from a matrix32s = ''33size = len(gate[0])34for row in range(size):35for column in range(size):36c, r = f'{column:02b}', f'{row:02b}'37s += f'\\class{{t_amp_{c}_{r}}}{{{gate[row][column]}}} & '38s = s[:-2]39s += '\\\\\n'40print(s)414243