from qiskit_aqua import register_pluggable
from evolutionfidelity.evolutionfidelity import EvolutionFidelity
try:
    register_pluggable(EvolutionFidelity)
except Exception as e:
    print(e)

from qiskit import Aer
import numpy as np
from qiskit_aqua.operator import Operator

from evolutionfidelity.evolutionfidelity import EvolutionFidelity
from qiskit_aqua.components.initial_states import Zero
from qiskit_aqua import QuantumInstance
num_qubits = 2
temp = np.random.random((2 ** num_qubits, 2 ** num_qubits))
qubit_op = Operator(matrix=temp + temp.T)

initial_state = Zero(qubit_op.num_qubits)

algo = EvolutionFidelity(qubit_op, initial_state, expansion_order=1)

backend = Aer.get_backend('statevector_simulator')
quantum_instance = QuantumInstance(backend=backend)

result = algo.run(quantum_instance)
print(result['score'])

from qiskit_aqua.input import EnergyInput
from qiskit_aqua import run_algorithm

params = {
    'problem': {
        'name': 'eoh'
    },
    'algorithm': {
        'name': 'EvolutionFidelity',
        'expansion_order': 1
    },
    'initial_state': {
        'name': 'ZERO'
    }
}

algo_input = EnergyInput(qubit_op)

result = run_algorithm(params, algo_input, backend=backend)
print(result['score'])