Ejemplo n.º 1
0
# Creating registers
qr = Q_program.create_quantum_register("qr", 2)
cr = Q_program.create_classical_register("cr", 2)

# hadamard on qubit-1 only
had = Q_program.create_circuit("had", [qr], [cr])
had.h(qr[1])

# CNOT gate with qubit 1 control, qubit 0 target (target for ibmqx4)
cnot = Q_program.create_circuit("cnot", [qr], [cr])
cnot.cx(qr[1], qr[0])

U_had = np.array([[1, 1], [1, -1]])/np.sqrt(2)
# compute Choi-matrix from unitary
had_choi = outer(vectorize(U_had))
plot_state(had_choi)

had_tomo_set = tomo.process_tomography_set([1],'Pauli','Pauli')
had_tomo_circuits = tomo.create_tomography_circuits(Q_program, 'had',qr,cr,had_tomo_set)


backend  =  'local_qasm_simulator'
shots = 1000
had_tomo_results = Q_program.execute(had_tomo_circuits, shots=shots, backend=backend)

had_process_data = tomo.tomography_data(had_tomo_results,'had', had_tomo_set)
had_choi_fit = tomo.fit_tomography_data(had_process_data,'leastsq',options={'trace':2})
plot_state(had_choi_fit,'paulivec')


#unitary matrix for CNOT with qubit 1 as control and qubit 0 as target.
Ejemplo n.º 2
0
# Execute the tomo circuits
tomo_results = Q_program.execute(tomo_circuits,
                                 shots=shots,
                                 backend=backend,
                                 timeout=300)

# Gather data from the results
tomo_data = tomo.tomography_data(tomo_results, 'FTSWAP', tomo_set)
swap_choi_fit = tomo.fit_tomography_data(tomo_data,
                                         'leastsq',
                                         options={'trace': 4})

# Define perfect results
U_swap = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
swap_choi = outer(vectorize(U_swap))

# Plot perfect and fitted results
print('Perfect Choi matrix for Swap operation:')
plot_state(swap_choi, 'city')

print('Fitted Choi matrix from simulations using tomography:')
plot_state(swap_choi_fit, 'city')

# Analyse data
print('Process Fidelity = ',
      state_fidelity(vectorize(U_swap) / 2, swap_choi_fit / 4))

diff = sum(sum(abs(swap_choi - swap_choi_fit))) / (2**2)
print('Total difference is:', diff)
Ejemplo n.º 3
0
import numpy as np
from qiskit import QuantumCircuit, QuantumProgram
import Qconfig


import qiskit.tools.qcvv.tomography as tomography

from qiskit.tools.visualization import plot_state, plot_histogram
from qiskit.tools.qi.qi import state_fidelity, concurrence, purity, outer

QProgram = QuantumProgram() 
QProgram.set_api(Qconfig.APItoken, Qconfig.config['url'])

qr = QProgram.create_quantum_register('qr',2)
cr = QProgram.create_classical_register('cr',2)

bell = QProgram.create_circuit('bell', [qr], [cr])
bell.h(qr[0])
bell.cx(qr[0], qr[1])

bell_result = QProgram.execute(['bell'], backend = 'local_qasm_simulator', shots = 1)
bell_psi = bell_result.get_data('bell') ['quantum_state']
bell_rho = outer(bell_psi)

plot_state(bell_rho, 'paulivec')
Ejemplo n.º 4
0
qr = QuantumRegister(2)
cr = ClassicalRegister(2)

# quantum circuit to make an entangled Bell state
bell = QuantumCircuit(qr, cr, name='bell')
bell.h(qr[1])
bell.cx(qr[1], qr[0])

#print(qiskit.available_backends())
job = qiskit.execute(bell, backend='local_statevector_simulator')
bell_psi = job.result().get_statevector(bell)
bell_rho = outer(
    bell_psi)  # construct the density matrix from the state vector

#plot the state
plot_state(bell_rho, 'paulivec')

# Construct state tomography set for measurement of qubits [0, 1] in the Pauli basis
bell_tomo_set = tomo.state_tomography_set([0, 1])

# Create a quantum program containing the state preparation circuit
Q_program = QuantumProgram()
Q_program.add_circuit('bell', bell)

# Add the state tomography measurement circuits to the Quantum Program
bell_tomo_circuit_names = tomo.create_tomography_circuits(
    Q_program, 'bell', qr, cr, bell_tomo_set)

print('Created State tomography circuits:')
for name in bell_tomo_circuit_names:
    print(name)
Ejemplo n.º 5
0
from qiskit import QuantumCircuit, QuantumProgram
import Qconfig
import qiskit.tools.qcvv.tomography as tomo
import numpy as np
from qiskit.tools.visualization import plot_state, plot_histogram
from qiskit.tools.qi.qi import state_fidelity, concurrence, purity, outer

p = QuantumProgram()
p.set_api(Qconfig.APItoken, Qconfig.config['url'])

qr = p.create_quantum_register('qr', 2)
cr = p.create_classical_register('cr', 2)

# quantum circuit to make an entangled bell state 
bell = p.create_circuit('bell', [qr], [cr])
bell.h(qr[0])
bell.cx(qr[0], qr[1])


bell_result = p.execute(['bell'], backend='local_qasm_simulator', shots=1)
bell_psi = bell_result.get_data('bell')['quantum_state']
bell_rho = outer(bell_psi) # construct the density matrix from the state vector


#plot_state(bell_rho,'paulivec')

rho_mixed = np.array([[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]])/2
plot_state(rho_mixed, 'paulivec')
Ejemplo n.º 6
0
# Put the qubits 0, 1, 2 in a GHZ state.
circ.cx(q[0], q[2]) # Add a CX (CNOT) gate on control qubit 0 and target qubit 2

# 1.2: Visualize the Circuit
circuit_drawer(circ, filename="Circuit.png").show()

# 2: Qiskit Aer (For Simulation purposes like QuTiP)

# 2.1: Run the quantum circuit on a statevector simulator backend
backend = Aer.get_backend('statevector_simulator')
job = execute(circ, backend) # Create a Quantum Program for execution 
result = job.result()
outputstate = result.get_statevector(circ)
print("simulation: ", result )
print(np.around(outputstate,3))
plot_state(outputstate)

# 2.2: Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(circ, backend)
result = job.result()
print("simulation: ", result )
print(np.around(result.get_unitary(circ), 3))

# 2.3: OpenQASM backend (QASM: Qiskit-Aer Simulating Measurement)
# To simulate a circuit that includes measurement, we need to add measurements 
# to the original circuit above, and use a different Aer backend.
c = ClassicalRegister(3, 'c') # Create a Classical Register with 3 bits.
meas = QuantumCircuit(q, c) # Create a Quantum Circuit
meas.barrier(q) # Create barrier figuratively? between operations & measurements
meas.measure(q,c) # map the quantum measurement to the classical bits