def qiskit():
    # Plotting Single Bloch Sphere
    plot_bloch_vector([0, 1, 0], title='Bloch Sphere')

    # Building Quantum Circuit to use for multiqubit systems
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0, 1)

    # Plotting Multi Bloch System
    state = Statevector.from_instruction(qc)
    plot_bloch_multivector(state, title="New Bloch Multivector")

    # Plotting Bloch City Scape
    plot_state_city(state,
                    color=['midnightblue', 'midnightblue'],
                    title="New State City")

    # Plotting Bloch Pauli Vectors
    plot_state_paulivec(state, color='midnightblue', title="New PauliVec plot")
Ejemplo n.º 2
0
 def qonduit_visualization_state_plot_state_paulivec(state):
     return interactive(lambda sv: display(plot_state_paulivec(sv)),
                        sv=fixed(state))
Ejemplo n.º 3
0
    def collisional_model(self,
                          backend='qasm_simulator',
                          live=False,
                          noise_model=None,
                          channel='amplitude_damping',
                          shots=1024,
                          measured_qubits=(),
                          max_collisions=5,
                          theta=np.pi / 2,
                          concurrence=False,
                          tangle=False,
                          witness=False,
                          tangle_witness=True,
                          markov=True,
                          print_results=True,
                          save_results=False,
                          directory=None,
                          full=True,
                          initial_statevector=np.array([0.5, 0.5])):

        self.channel = channel
        self.markov = markov

        if self.state == 'h':
            self.qc.h(0)

        elif self.state == 'GHZ_teleport':
            initial_state = initial_statevector
            initial_state /= np.linalg.norm(initial_state)
            self.qc.initialize(initial_state, [0])
            self.theoretical_rho = np.outer(initial_state, initial_state)
            self.GHZ([1, 2, 3])

        elif self.state == 'D':
            self.D()
            if full:
                self.theoretical_rho = self.full_theoretical_D(self.n, self.k)
            else:
                self.theoretical_rho = self.theoretical_D(self.n, self.k)

        elif self.state == 'W':
            self.W()
            if full:
                self.theoretical_rho = self.full_theoretical_D(self.n, self.k)
            else:
                self.theoretical_rho = self.theoretical_D(self.n, self.k)

        elif self.state == 'GHZ':
            self.GHZ(range(self.n))
            if full:
                self.theoretical_rho = self.full_theoretical_GHZ(self.n)
            else:
                self.theoretical_rho = self.theoretical_GHZ(self.n)

        self.histogram_data = []
        self.directory = directory

        if backend == 'qasm_simulator':
            self.backend = Aer.get_backend('qasm_simulator')
            self.coupling_map = None
            if noise_model:
                self.noise_model = noise_model
                self.basis_gates = self.noise_model.basis_gates
            else:
                self.noise_model = None
                self.basis_gates = None
        else:
            provider = IBMQ.get_provider(group='open')
            self.device = provider.get_backend(backend)
            self.properties = self.device.properties()
            self.coupling_map = self.device.configuration().coupling_map
            self.noise_model = noise.device.basic_device_noise_model(
                self.properties)
            self.basis_gates = self.noise_model.basis_gates

            if save_results:
                visual.plot_error_map(self.device).savefig(
                    '{}/error_map.png'.format(self.directory))

            if live:
                check = input(
                    "Are you sure you want to run the circuit live? [y/n]: ")
                if check == 'y' or check == 'yes':
                    self.backend = self.device
                else:
                    self.backend = Aer.get_backend('qasm_simulator')
            else:
                self.backend = Aer.get_backend('qasm_simulator')

        self.unitary_backend = Aer.get_backend('unitary_simulator')

        self.shots = shots

        if self.state == 'GHZ_teleport':
            self.a = 3
            self.b = 3
        elif measured_qubits == ():
            self.a = 0
            self.b = self.n - 1
        else:
            self.a = measured_qubits[0]
            self.b = measured_qubits[1]

        self.max_collisions = max_collisions
        self.theta = theta

        if self.max_collisions > 0:
            if self.channel == 'phase_damping_one_qubit':
                self.ancilla = QuantumRegister(1, 'a')
                self.qc.add_register(self.ancilla)
            elif not markov:
                self.ancilla = QuantumRegister(3, 'a')
                self.qc.add_register(self.ancilla)
                self.qc.h(self.ancilla[2])
                self.qc.cx(self.ancilla[2], self.ancilla[1])
                self.qc.cx(self.ancilla[1], self.ancilla[0])
            else:
                self.ancilla = QuantumRegister(self.max_collisions, 'a')
                self.qc.add_register(self.ancilla)

        if self.channel == 'amplitude_damping':
            self.U = self.amplitude_damping_operator(full)
        elif self.channel == 'phase_damping' or 'phase_damping_one_qubit':
            self.U = self.phase_damping_operator(full)
        elif self.channel == 'heisenberg':
            print('Not yet programmed')
            quit()
            self.U = self.heisenberg_operator()

        if tangle_witness:
            self.tangle_witness_GHZ = 3 / 4 * np.kron(np.kron(
                I, I), I) - self.full_theoretical_GHZ(3)
            self.tangle_witness_tri = 1 / 2 * np.kron(np.kron(
                I, I), I) - self.full_theoretical_GHZ(3)

        counts_list = []
        rho_list = []
        theoretical_rho_list = []
        concurrence_list = []
        theoretical_concurrence_list = []
        tangle_ub_list = []
        tangle_lb_list = []
        theoretical_tangle_list = []
        fidelity_list = []
        witness_list = []
        tangle_witness_GHZ_list = []
        tangle_witness_tri_list = []
        trace_squared_list = []
        for k in range(self.max_collisions + 1):
            if k > 0:
                self.collision(k)
                if witness:
                    counts = self.measure(witness)
                else:
                    rho = self.tomography(full)
                    self.evolve_theoretical_rho(full)
            else:
                if witness:
                    counts = 1 / 2
                else:
                    rho = self.tomography(full)

            if save_results:
                visual.plot_state_city(rho).savefig(
                    '{}/state_city_{}.png'.format(self.directory, k))
                visual.plot_state_paulivec(rho).savefig(
                    '{}/paulivec_{}.png'.format(self.directory, k))

            if witness:
                counts_list.append(counts)
            else:
                rho_list.append(rho)
                theoretical_rho_list.append(self.theoretical_rho)
                if not full and self.state != 'GHZ_teleport':
                    C = self.concurrence(rho)
                    concurrence_list.append(C)
                    TC = self.concurrence(self.theoretical_rho)
                    theoretical_concurrence_list.append(TC)
                if tangle:
                    T_ub = self.tangle_ub(rho)
                    tangle_ub_list.append(T_ub)
                    #T_lb = self.tangle_lb(rho)
                    #tangle_lb_list.append(T_lb)
                    if self.state == 'GHZ':
                        TT = np.exp(np.log(np.cos(self.theta)) * k)
                        theoretical_tangle_list.append(TT)
                F = state_fidelity(theoretical_rho_list[0], rho)
                fidelity_list.append(F)
                if witness:
                    W = np.real(
                        np.trace(
                            np.matmul(self.full_theoretical_GHZ(self.n), rho)))
                    witness_list.append(W)
                if tangle_witness and full:
                    TWGHZ = np.real(
                        np.trace(np.matmul(self.tangle_witness_GHZ, rho)))
                    tangle_witness_GHZ_list.append(TWGHZ)
                    TWtri = np.real(
                        np.trace(np.matmul(self.tangle_witness_tri, rho)))
                    tangle_witness_tri_list.append(TWtri)
                Tr2 = np.real(np.trace(np.matmul(rho, rho)))
                trace_squared_list.append(Tr2)

                if print_results:
                    print("Collision Number:", k)
                    print("Original Density Matrix:")
                    print(theoretical_rho_list[0])
                    print("Theoretical Density Matrix:")
                    print(self.theoretical_rho)
                    print("Measured Density Matrix:")
                    print(rho)
                    print("Trace:", np.real(np.trace(rho)))
                    print("Trace Squared:", Tr2)
                    if concurrence:
                        print("Concurrence:", C)
                        print("Theoretical Concurrence:", TC)
                    if tangle:
                        print("Tangle Upper Bound:", T_ub)
                        #print("Tangle Lower Bound:", T_lb)
                        print("Theoretical Tangle:", TT)
                    print("Fidelity:", F)
                    if witness:
                        print("Witness:", W)
                    if tangle_witness and full:
                        print("GHZ Tangle Witness:", TWGHZ)
                        print("Tripartite Tangle Witness:", TWtri)
                    print("Eigenvalues:",
                          np.sort(np.real(np.linalg.eigvals(rho)))[::-1])
                    print(
                        "\n-----------------------------------------------------------------------------------\n"
                    )

        if print_results:
            if save_results:
                visual.circuit_drawer(
                    self.qc,
                    filename='{}/constructed_circuit.png'.format(
                        self.directory),
                    output='mpl')
            else:
                print(self.qc)
            print("Constructed Circuit Depth: ", self.qc.depth())
            try:
                transpiled_qc = transpile(self.qc,
                                          self.device,
                                          optimization_level=3)
                if save_results:
                    visual.circuit_drawer(
                        transpiled_qc,
                        filename='{}/transpiled_circuit.png'.format(
                            self.directory),
                        output='mpl')
                print("Transpiled Circuit Depth: ", self.qc.depth())
            except:
                pass
            print()

        if save_results:
            visual.plot_histogram(
                self.histogram_data, title=self.state).savefig(
                    '{}/histogram.png'.format(self.directory))

        return counts_list, theoretical_rho_list, rho_list, theoretical_concurrence_list, concurrence_list, \
               theoretical_tangle_list, tangle_ub_list, tangle_lb_list, fidelity_list, witness_list, \
               tangle_witness_GHZ_list, tangle_witness_tri_list, trace_squared_list
Ejemplo n.º 4
0
plot_histogram([counts, second_counts], legend=legend)

plot_histogram([counts, second_counts],
               legend=legend,
               sort='desc',
               figsize=(15, 12),
               color=['orange', 'black'],
               bar_labels=False)

from qiskit.visualization import plot_state_city, plot_bloch_multivector
from qiskit.visualization import plot_state_paulivec, plot_state_hinton
from qiskit.visualization import plot_state_qsphere

backend = BasicAer.get_backend('statevector_simulator')
result = execute(bell, backend).result()
psi = result.get_statevector(bell)

plot_state_city(psi)

plot_state_hinton(psi)

plot_state_qsphere(psi)

plot_state_paulivec(psi)

plot_bloch_multivector(psi)

plot_state_city(psi, title="My City", color=['black', 'orange'])

plot_state_hinton(psi, title="My Hinton")