qiskit-community / ibm-quantum-challenge-2024

For IBM Quantum Challenge 2024 (5-14 June 2024)
https://challenges.quantum.ibm.com/2024
Apache License 2.0
158 stars 240 forks source link

Problem in submitting the function to grader (ibm challenge 2024) #24

Closed atul20027 closed 3 months ago

atul20027 commented 3 months ago

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 3 months ago

Include the hamiltonian and the parameters in a list: [hamiltonean] , [params]