Given this code:
import numpy as np
from qiskit import QuantumCircuit, Aer, execute
def calculate_hydrogen_energy():
# Definir el circuito cuántico
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
# Simular el circuito cuántico
simulator = Aer.get_backend('qasm_simulator')
job = execute(circuit, simulator, shots=1000)
result = job.result()
counts = result.get_counts(circuit)
I changed it a little bit, by installing qiskit-aer, and consulting this question: Unable to import execute function from qiskit library, and seeing this page about the migration from execute to transpile https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0-features#execute. The result was the next code:
import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit_aer import Aer
def calculate_hydrogen_energy():
# Definir el circuito cuántico
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
# Simular el circuito cuántico
simulator = Aer.get_backend('qasm_simulator')
job = transpile(circuit, simulator, shots=1000)
result = job.result()
counts = result.get_counts(circuit)
But this code displays me the next error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[13], line 29
26 return energy
28 # Obtener el resultado de la energía
---> 29 hydrogen_energy = calculate_hydrogen_energy()
30 print("Energía de la molécula de Hidrógeno:", hydrogen_energy)
Cell In[13], line 13, in calculate_hydrogen_energy()
11 # Simular el circuito cuántico
12 simulator = Aer.get_backend('qasm_simulator')
---> 13 job = transpile(circuit, simulator, shots=1000)
14 result = job.result()
15 counts = result.get_counts(circuit)
TypeError: transpile() got an unexpected keyword argument 'shots'
I was trying to investigate about how can I replace or find an alternative in the “unexpected keyword argument ‘shots’ ” in the documentation, but I don’t understand deeply what is said. Also I don’t want to use an older version of qiskit, as suggested in the answer two of the question given in Unable to import execute function from qiskit library. So, How can I fix this issue?
Simón Xolocotzi Muñoz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.