Problem in submitting the function to grader (ibm challenge 2024)
atul20027 opened this issue · 1 comments
atul20027 commented
Already i have implemented the code but when i am submitting to grade_lab1_ex6 it is giving error " you need to implement the code to get the result".
def cost_func(params, ansatz, hamiltonian, estimator,callback1_dict):
"""Return estimate of energy from estimator
Parameters:
params (ndarray): Array of ansatz parameters
ansatz (QuantumCircuit): Parameterized ansatz circuit
hamiltonian (SparsePauliOp): Operator representation of Hamiltonian
estimator (EstimatorV2): Estimator primitive instance
Returns:
float: Energy estimate
"""
pub = (ansatz,hamiltonian,params)
result = estimator.run([pub])
energy = result.result()[0].data.evs
#return energy,result
callback1_dict["iters"] += 1
callback1_dict["prev_vector"] = params
callback1_dict["cost_history"].append(result)
Don't change any code past this line
print(energy)
return energy, result
grade_lab1_ex6(cost_func) ## while running this, got the below error
error : [0.70898438]
You need to implement code to get a result.
jgonzal3 commented
Include the hamiltonian and the parameters in a list: [hamiltonean] , [params]