from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

# Create a Quantum Circuit acting on the q register
circuit = QuantumCircuit(1)

# print the statevector
print(f"Initial Statevector: {Statevector.from_instruction(circuit).data}\n\n")

# Add an X gate followed by a H gate to put the qubit in |-> state
circuit.x(0)
circuit.h(0)

print("After putting the qubit in |-> state\n\n")

# print the statevector
print("Final Statevector: ", Statevector.from_instruction(circuit).data)

import numpy as np
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info import Statevector

# Create a Quantum Register with 3 qubits
q = QuantumRegister(3)

# Create a Quantum Circuit acting on the q register to demonstrate the GHZ state
circuit = QuantumCircuit(q)

# Add a H gate on qubit 0, putting this qubit in superposition.
circuit.h(q[0])

# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circuit.cx(q[0], q[1])

# Add a CX (CNOT) gate on control qubit 0 and target qubit 2
circuit.cx(q[0], q[2])


from qiskit.quantum_info import Statevector

# Set the intial state of the simulator to the ground state using from_int
state = Statevector.from_int(0, 2**3)

# Evolve the state by the quantum circuit
state = state.evolve(circuit)

#draw using latex
state.draw('latex')

from qiskit.visualization import array_to_latex

#Alternative way of representing in latex
array_to_latex(state)

state.draw('qsphere')