Created
January 5, 2021 09:27
-
-
Save BankNatchapol/457dd6a45cbc088adc5f46d9b874a49f to your computer and use it in GitHub Desktop.
Pretty Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import classical | |
import quantum | |
import pandas as pd | |
from IPython.core import display as ICD | |
sbits = [0, 1] | |
tbits = [(0, 0), (0, 1), (1, 0), (1, 1)] | |
tables = [] | |
classicalTable = pd.DataFrame(columns=['bit', 'not']) | |
quantumTable = pd.DataFrame(columns=['Qbit', 'not']) | |
for bit in sbits: | |
classicalTable = classicalTable.append({'bit': bit, | |
'not': classical.not_gate(bit)}, | |
ignore_index=True) | |
quantumTable = quantumTable.append({'Qbit': "|" + str(bit) + "⟩", | |
'not': "|" + str(quantum.not_gate(bit)) + "⟩"}, | |
ignore_index=True) | |
print('Gate', 'not') | |
ICD.display(classicalTable) | |
ICD.display(quantumTable) | |
gates = [('and', classical.and_gate, quantum.and_gate), | |
('or', classical.or_gate, quantum.or_gate), | |
('xor', classical.xor_gate, quantum.xor_gate)] | |
for i in range(len(gates)): | |
classicalTable = pd.DataFrame(columns=['bit1', 'bit2', gates[i][0]]) | |
quantumTable = pd.DataFrame(columns=['Qbit1', 'Qbit2', gates[i][0]]) | |
for bit in tbits: | |
classicalTable = classicalTable.append({'bit1': bit[0], | |
'bit2': bit[1], | |
gates[i][0]: gates[i][1](bit[0], | |
bit[1])}, | |
ignore_index=True) | |
quantumTable = quantumTable.append({'Qbit1': "|" + str(bit[0]) + "⟩", | |
'Qbit2': "|" + str(bit[1]) + "⟩", | |
gates[i][0]: "|" + str(gates[i][2](bit[0], | |
bit[1])) + "⟩"}, | |
ignore_index=True) | |
print('Gate', gates[i][0]) | |
ICD.display(classicalTable) | |
ICD.display(quantumTable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment