import numpy as np

# Import Qiskit
from qiskit import QuantumCircuit, transpile
from qiskit_qulacs import QulacsProvider
from qiskit_qulacs.qulacs_backend import QulacsBackend
from qiskit.visualization import plot_histogram, plot_state_city
import qiskit.quantum_info as qi

seed = 42
np.random.seed(seed)

provider = QulacsProvider()

qulacs_simulator = provider.get_backend("qulacs_simulator")
qulacs_simulator

qulacs_simulator.available_devices()

# Create circuit
circ = QuantumCircuit(2)
circ.h(0)
circ.cx(0, 1)

# Transpile for simulator
qulacs_simulator = QulacsBackend()
circ = transpile(circ, qulacs_simulator)

# Run and get statevector
result = qulacs_simulator.run(circ).result()
statevector = result.get_statevector()
plot_state_city(statevector, title="Bell state")

result = qulacs_simulator.run(circ, shots=1024, seed_simulator=seed).result()
counts = result.get_counts()
plot_histogram(counts, title="Bell-State counts")

# Run and get memory
result = qulacs_simulator.run(circ, shots=10, seed_simulator=seed).result()
memory = result.get_memory()
print(memory)

# Create circuit
circ = QuantumCircuit(1)
for i in range(1000):
    circ.h(0)

qulacs_simulator = QulacsBackend()

backend_options = {
    "qco_enable": True,  # Enables the QuantumCircuitOptimizer
    "qco_method": "light",  # Uses light method for circuit optimization from qulacs
}

qulacs_simulator.set_options(**backend_options)

# Run and get statevector
result = qulacs_simulator.run(circ).result()
statevector = result.get_statevector()
print(statevector.real)

import qiskit

qiskit.__version__