Esempi di circuiti


Vediamo ora 2 esempi di circuiti quantistici con i quali possiamo ottenere i valori 2 o 3 in base decimale.



from qiskit import *
from qiskit.tools.visualization import plot_histogram
%matplotlib inline

def to_decimale(data):
return int(data, 2)

circuit = QuantumCircuit(4,2)
circuit.x(0)
circuit.x(1)
circuit.barrier()

circuit.cx(0,2)
circuit.cx(1,3)
circuit.barrier()

circuit.measure(2,1)
circuit.measure(3,0)

circuit.draw(output='mpl')




simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit, simulator, shots=1024).result()
counts = result.get_counts()
plot_histogram(counts)




ris = [k for k, v in counts.items() if v == max(counts.values())]
print('Risultato in decimali ....' ,to_decimale(ris[0] ))
Risultato in decimali .... 3


from qiskit import *
from qiskit.tools.visualization import plot_histogram
%matplotlib inline

def to_decimale(data):
return int(data, 2)

circuit = QuantumCircuit(4,2)
circuit.x(0)
circuit.x(1)
circuit.barrier()

circuit.cx(0,2)
circuit.cx(1,3)
circuit.ccx(0,1,3) circuit.barrier()

circuit.measure(2,1)
circuit.measure(3,0)

circuit.draw(output='mpl')




simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit, simulator, shots=1024).result()
counts = result.get_counts()
plot_histogram(counts)




ris = [k for k, v in counts.items() if v == max(counts.values())]
print('Risultato in decimali ....' ,to_decimale(ris[0] ))
Risultato in decimali .... 2