qc2 = QuantumCircuit(q2) qc2.x(q2) qc2.h(q2[0]) qc2.cx(q2[0], q2[1]) # In[5]: #Dibujo del circuito qc.draw(output='mpl') # In[6]: #State vector backend = Aer.get_backend('statevector_simulator') Statevector1 = execute(qc, backend).result().get_statevector() array_to_latex(Statevector1, pretext="\\text{Statevector1 = }") # In[7]: #Dibujo del segundo circuito qc2.draw(output='mpl') # In[8]: #State vector segundo circuito backend = Aer.get_backend('statevector_simulator') Statevector2 = execute(qc2, backend).result().get_statevector() array_to_latex(Statevector2, pretext="\\text{Statevector2 = }") # In[9]:
n = 2 t = 2 N = 1 M = 4 qc = QuantumCircuit(n,t) GC = initialize_s(qc, range(n)) GC.measure_all() #ceate the CR1 schedule # The Unitary is an identity (with a global phase) backend = qiskit.Aer.get_backend('unitary_simulator') basis_gates = ['u1','u2','u3','cx'] # use U,CX for now job = qiskit.execute(qc, backend=backend, basis_gates=basis_gates) from qiskit_textbook.tools import array_to_latex array_to_latex(np.around(job.result().get_unitary(),3), pretext="\\text{Unitary} = ") #Add the CR1 instruction to basis_gates and inst_map basis_gates += ['cr1'] inst_map.add(gate_name, [1,0], sched) #Create a quantum gate to reference the CR1 pulse schedule cr1_gate = Gate(gate_name, 2, []) #Create the QPT circuits qregs = QuantumRegister(config.n_qubits) circuit = QuantumCircuit(qregs) circuit.append(cr1_gate, qargs = [qregs[1], qregs[0]]) qpt_circuits = process_tomography_circuits(circuit, [qregs[0], qregs[1]]) #Create the QPT pulse scchedules
# In[2]: #Construimos un circuito con 3 registros qc = QuantumCircuit(3) #aplicamos la compuerta H al primer registro qc.h(0) #luego aplicamos CNOT en registros 0 y 1, luego 1 y 2 qc.cx(0, 1) qc.cx(1, 2) # In[3]: #Dibujo del circuito qc.draw(output='mpl') # In[4]: #State vector backend = Aer.get_backend('statevector_simulator') final_state = execute(qc, backend).result().get_statevector() array_to_latex(final_state, pretext="\\text{Statevector = }") # In[5]: #Histograma de los resultados results = execute(qc, backend).result().get_counts() plot_histogram(results) # In[6]:
qc.h(q[0]) # In[30]: #Dibujo del circuito qc.draw(output='mpl') # In[31]: #Mostramos resultado como compuerta unitaria, se puede observar como resultado el CNOT backend = Aer.get_backend('unitary_simulator') unitary = execute(qc, backend).result().get_unitary() # In[32]: array_to_latex(unitary, pretext="\\text{Circuit = }\n") # In[33]: #Resultado del state vector backend = Aer.get_backend('statevector_simulator') final_state = execute(qc, backend).result().get_statevector() array_to_latex(final_state, pretext="\\text{Statevector = }") # In[34]: results = execute(qc, backend).result().get_counts() plot_histogram(results) # In[ ]:
import numpy as np import matplotlib.pyplot as plt from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, BasicAer, IBMQ from qiskit.extensions import Initialize from qiskit.visualization import plot_histogram, plot_bloch_multivector from qiskit_textbook.tools import random_state, array_to_latex psi = random_state(1) # Display it nicely array_to_latex(psi, pretext="|\\psi\\rangle =") # Show it on a Bloch sphere plot_bloch_multivector(psi) plt.show() init_gate = Initialize(psi) init_gate.label = "init" inverse_init_gate = init_gate.gates_to_uncompute() def create_bell_pair(qc, a, b): qc.h(a) qc.cx(a, b) def alice_gates(qc, psi, a): qc.cx(psi, a) qc.h(psi)