import numpy as np
import qtda_module as qtda
from qiskit.visualization import plot_histogram
from qiskit import IBMQ
from qiskit import execute, QuantumRegister, QuantumCircuit, ClassicalRegister, Aer
from qiskit.compiler import transpile

provider = IBMQ.load_account()
accountProvider = IBMQ.get_provider(hub='ibm-q-fraunhofer',group = 'fhg-all',project = 'ticket')
backend = accountProvider.get_backend('ibmq_brooklyn') 

n_vertices = 3 # number of vertices
num_eval_qubits = 3 # number of evaluation qubits

S0 = [(0,0,1),(0,1,0), (1,0,0)] # points
S1 = [(1,0,1),(0,1,1),(1,1,0)] # lines
S2 = []

state_dict = {0: S0, 1: S1, 2: S2}
k = 1 # order of the combinatorial Laplacian
qc = qtda.QTDAalgorithm(num_eval_qubits, k, state_dict)

qc.add_register(ClassicalRegister(num_eval_qubits)) # adding a classical register for measuring
for q in qc.eval_qubits: # measure all evaluation qubits
    qc.measure(q,q)
qc.draw('mpl')

qcc = transpile(qc, basis_gates=['id', 'rz', 'sx', 'x', 'cx'], layout_method='sabre',optimization_level=3)

qa = transpile(qc, backend=backend, basis_gates=['id', 'rz', 'sx', 'x', 'cx'],layout_method='sabre',optimization_level=3)

qa.depth() # depth of ibmq_brooklyn

qcc.depth() # depth of an arbitrary backend

shots = 8192
job = execute(qa, backend, shots=shots)
counts = job.result().get_counts(qa)

dim = len(state_dict[1]) # dimension of 1-simplex space
prob = counts.get("0"*num_eval_qubits)/shots # probability of eigenvalue 0

print('The number of 1-holes is', dim * prob)
plot_histogram(counts)

import qiskit
qiskit.__qiskit_version__

