import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, assemble, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
# Importing basic math libraries
from math import pi, sqrt

# Loading your IBM Q account(s)
provider = IBMQ.load_account()

# Definining the simulator: statevector_simulator, or qasm_simulator
simulator = "statevector_simulator"

# Function to plot the Quantum Circuit / Quantum State
def get_plot(quantum_circuit):
    """
    Parameters:
    quantum_circuit: The Quantum Circuit to visualize
    Returns:
    return: Plot/Visualization of the Quantum State
    """
    sim = Aer.get_backend(simulator)
    quantum_object = assemble(quantum_circuit)
    if simulator == "statevector_simulator":
        result = sim.run(quantum_object).result()
        statevector = result.get_statevector()
        return plot_bloch_multivector(statevector)
    elif simulator == "qasm_simulator":
        result = sim.run(quantum_object).result()
        count = result.get_counts()
        return plot_histogram(count)

# Creating a single qubit Quantum Circuit
num_qubits = 1
qc = QuantumCircuit(num_qubits) # Creates a Quantum Circuit with 1 qubit

# Visualizing the Quantum Wire
qc.draw() # Drawing the Quantum Circuit

# Visualizing the Quantum Circuit using Simulator
get_plot(qc) # Drawing the Quantum Circuit

# Pauli-X Gate Demonstration
# Let's do an X-gate on a |0> qubit
qc.x(0) # Applies Pauli-X Gate to the |0> qubit
qc.draw() # Drawing the Quantum Circuit

# Visualize the Quantum Circuit using Simulator
get_plot(qc)