Qiskit / qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
https://qiskit.github.io/qiskit-aer/
Apache License 2.0
503 stars 361 forks source link

Unable to obtain FakeAlmaden model #1192

Closed haoqindeng closed 3 years ago

haoqindeng commented 3 years ago

Informations

What is the current behavior?

We attempted to run the following code:

backend = FakeAlmaden()
fakealmaden_model = PulseSystemModel.from_backend(backend)

and we get the following error:

(vqe) haoqindeng@LAPTOP-CE39QN05:/mnt/c/Users/haoqi/OneDrive/Desktop/QOC$ python qoc_test2.py line 45
Traceback (most recent call last):
  File "qoc_test2.py", line 46, in <module>
    fakealmaden_model = PulseSystemModel.from_backend(backend)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/pulse_system_model.py", line 106, in from_backend
    return cls.from_config(config, subsystem_list)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/pulse_system_model.py", line 116, in from_config
    hamiltonian = HamiltonianModel.from_dict(ham_string, subsystem_list)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/hamiltonian_model.py", line 130, in from_dict
    system.parse(subsystem_list)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/string_model_parser/string_model_parser.py", line 97, in parse
    coef, token = self._tokenizer(ham, qubit_list)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/string_model_parser/string_model_parser.py", line 183, in _tokenizer
    opr = gen_oper(name, idx, self.dim_osc, self.dim_qub)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/string_model_parser/qobj_from_string.py", line 79, in gen_oper
    return qobj_generators.tensor(opers)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/qutip_extra_lite/qobj_generators.py", line 101, in tensor
    return ten.tensor(list_qobj)
  File "/home/haoqindeng/miniconda3/envs/vqe/lib/python3.7/site-packages/qiskit/providers/aer/pulse/qutip_extra_lite/tensor.py", line 103, in tensor
    out.data = zcsr_kron(out.data, q.data)
  File "spmath.pyx", line 188, in qiskit.providers.aer.pulse.qutip_extra_lite.cy.spmath.zcsr_kron
  File "spmath.pyx", line 422, in qiskit.providers.aer.pulse.qutip_extra_lite.cy.spmath._safe_multiply
OverflowError: value too large

Steps to reproduce the problem

import qiskit
from qiskit import transpile, schedule as build_schedule
from qiskit.test.mock import FakeAlmaden
from qiskit import Aer, IBMQ, execute
from qiskit import QuantumCircuit
from qiskit.circuit import Gate

from qiskit import pulse
from qiskit.ignis.characterization.calibrations import rabi_schedules, RabiFitter

from qiskit.pulse import DriveChannel
from qiskit.compiler import assemble
from qiskit.qobj.utils import MeasLevel, MeasReturnType
# The pulse simulator
from qiskit.providers.aer import PulseSimulator

# Object for representing physical models
from qiskit.providers.aer.pulse import PulseSystemModel

# Mock Armonk backend
from qiskit.test.mock.backends.armonk.fake_armonk import FakeArmonk

# backend = qiskit.providers.aer.PulseSimulator()
backend = FakeAlmaden()
print(backend.configuration().hamiltonian)
# schedule = build_schedule(transpiled_circ, backend)
circ = QuantumCircuit(2, 2)
circ.x(0)
circ.x(0)
circ.x(1)
circ.measure([0, 1], [0, 1])

schedule = build_schedule(circ, backend,
                          method="as_late_as_possible")
# schedule.draw(channels=[pulse.DriveChannel(0), pulse.DriveChannel(1)])

backend_sim = PulseSimulator()

qobj = assemble(schedule,
                     backend=backend_sim,
                     meas_level=1,
                     meas_return='avg',
                     shots=1)
print('line 45')
fakealmaden_model = PulseSystemModel.from_backend(backend)
print('line47')
sim_result = backend_sim.run(qobj, fakealmaden_model).result()

What is the expected behavior?

We should be able to run the code at the line: fakealmaden_model = PulseSystemModel.from_backend(backend) instead of getting the error above.

Suggested solutions

Don't know how. Any ideas? @taalexander

nonhermitian commented 3 years ago

You cannot build a sparse representation of a system model that big. That is what the error is indicating.

haoqindeng commented 3 years ago

Our ultimate goal is to get the last line "sim_result = backend_sim.run(qobj, fakealmaden_model).result()" to work, but we are currently struck at error at "fakealmaden_model = PulseSystemModel.from_backend(backend)". Basically we are trying to extract a schedule of a circuit "circ" with FakeAlmaden backend, then use this schedule to construct a qobj and run it with fakealmaden_model.

If we cannot build a model that big, what do you suggest we could do to execute the qobj and obtain the results? @nonhermitian

DanPuzzuoli commented 3 years ago

Since it looks like you are only trying to run a schedule on the qubits 0 and 1, when constructing the PulseSystemModel, you can do:

fakealmaden_model = PulseSystemModel.from_backend(backend, subsystem_list=[0, 1])

This will tell the constructor to only construct the model for just qubits 0 and 1.