我收到 'No memory for the experiment' 错误,虽然我没有看到任何错误
I am getting 'No memory for the experiment' error although i dont see any mistake
我正在尝试执行此代码,但收到此错误 'No memory for the experiment'。任何人都可以帮我解决我还需要导入什么来获取电路的记忆吗?
from qiskit.providers.aer import QasmSimulator
# Create a quantum circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Get the Qasm simulator and set the backend options
aer_qasm_simulator = Aer.get_backend('qasm_simulator')
# Set the backend options, method set to statevector
options = {'method': 'statevector', 'memory' : True, 'shots':10}
# Execute circuit using the backend options created
job = execute(qc, backend_simulator, backend_options=options)
result = job.result()
# Pull the memory slots for the circuit
memory = result.get_memory(qc)
# Print the results from the memory slots
print('Memory results: ', memory)```
您的代码的问题在于 memory
和 shots
不是后端选项,而是 execute
参数:
# Set the backend options, method set to statevector
options = {'method': 'statevector'}
# Execute circuit using the backend options created
job = execute(qc, aer_qasm_simulator, backend_options=options, memory=True, shots=10)
这将解决您的问题。
旁注:Qiskit moving away from the execute
model 因为除其他外,它造成了这种混乱。
当前(2022 年 5 月)您正在做的事情如下:
from qiskit import QuantumCircuit, Aer, transpile
from qiskit.providers.aer import QasmSimulator
# Create a quantum circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Get the statevector simulator
aer_simulator_statevector = Aer.get_backend('aer_simulator_statevector')
# Transpile for the backend. Strictly speacking, not necesary in this case
qc = transpile(qc, aer_simulator_statevector)
# Pull the memory slots for the circuit
result = aer_simulator_statevector.run(qc, shots=10, memory=True).result()
memory = result.get_memory(qc)
# Print the results from the memory slots
print('Memory results: ', memory)
欢迎来到 Whosebug 社区 :)
我正在尝试执行此代码,但收到此错误 'No memory for the experiment'。任何人都可以帮我解决我还需要导入什么来获取电路的记忆吗?
from qiskit.providers.aer import QasmSimulator
# Create a quantum circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Get the Qasm simulator and set the backend options
aer_qasm_simulator = Aer.get_backend('qasm_simulator')
# Set the backend options, method set to statevector
options = {'method': 'statevector', 'memory' : True, 'shots':10}
# Execute circuit using the backend options created
job = execute(qc, backend_simulator, backend_options=options)
result = job.result()
# Pull the memory slots for the circuit
memory = result.get_memory(qc)
# Print the results from the memory slots
print('Memory results: ', memory)```
您的代码的问题在于 memory
和 shots
不是后端选项,而是 execute
参数:
# Set the backend options, method set to statevector
options = {'method': 'statevector'}
# Execute circuit using the backend options created
job = execute(qc, aer_qasm_simulator, backend_options=options, memory=True, shots=10)
这将解决您的问题。
旁注:Qiskit moving away from the execute
model 因为除其他外,它造成了这种混乱。
当前(2022 年 5 月)您正在做的事情如下:
from qiskit import QuantumCircuit, Aer, transpile
from qiskit.providers.aer import QasmSimulator
# Create a quantum circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Get the statevector simulator
aer_simulator_statevector = Aer.get_backend('aer_simulator_statevector')
# Transpile for the backend. Strictly speacking, not necesary in this case
qc = transpile(qc, aer_simulator_statevector)
# Pull the memory slots for the circuit
result = aer_simulator_statevector.run(qc, shots=10, memory=True).result()
memory = result.get_memory(qc)
# Print the results from the memory slots
print('Memory results: ', memory)
欢迎来到 Whosebug 社区 :)