Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3312 | Large Pulse backend mock #3797

Merged
merged 38 commits into from
May 6, 2020

Conversation

IceKhan13
Copy link
Member

Summary

Create a large (100Q) Pulse backend mock and/or create a util method or a script to generate reasonable Pulse-enabled backend

Issue #3312

Details and comments

The pulse module of Qiskit has yet to be benchmarked. The purpose of benchmarking is to provide a deterministic way to assess performance of software over time. There is room for improvement in the performance of pulse operations; building benchmarks will allow us to quantify progress and justify code refactors.

Copy link
Contributor

@lcapelluto lcapelluto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's exciting to see this getting started! Thank you @IceKhan13 :)

qiskit/test/mock/backends/fake_100q/conf_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor

@taalexander taalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming along nicely @IceKhan13. I think you are on the right track with the FakeBackendBuilder. What I would like to see is an arbitrary FakeBackendBuilder that you can pass a number of qubits too, a grid size and potentially just examples for single-qubit properties and frequencies. We could then provide a FakeOpenPulse100Q or FakeOpenPulse1000Q which upon calling would generate the fake backend. This would remove the need for storing configuration and properties json.

For example

def fake_backend_generator(n_qubits, name, coupling_map=None, version='1.1', pulse=True, basis_gates=['id', 'u1', 'u2', 'u3', 'cx'], 1q_error_rate=0.001, 2q_error_rate=0.01, T1=100, T2=200) -> FakeBackend:
    ...

and then we would have

FakeOpenPulse100Q = fake_backend_generator(100, ...)
FakeOpenPulse1000Q = fake_backend_generator(1000, ...)

Note the backend generation shouldn't actually happen until the mock backend is instantiated, ie., calling FakeOpenPulse100Q() should cause the backend to be generated. These generated backends could then be tested by the tests described here #3892.

qiskit/test/mock/backends/__init__.py Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/conf_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/conf_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/defs_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/defs_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/defs_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/props_100q.json Outdated Show resolved Hide resolved
qiskit/test/mock/backends/fake_100q/fake_100q.py Outdated Show resolved Hide resolved
…o utils package; props generation; TODO: build conf, tests
Copy link
Contributor

@taalexander taalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming along nicely, a couple of comments here and then we should figure out how to test this.

qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
qiskit/test/mock/utils/backend.py Outdated Show resolved Hide resolved
@IceKhan13
Copy link
Member Author

Team, I need some input from you 😄
I'm trying to write tests for generated by builder backends (create circuit and run it on the backend.)

It goes as usual:

desired_vector = [1 / math.sqrt(2), 0, 0, 1 / math.sqrt(2)]
qr = QuantumRegister(2, "qr")
qc = QuantumCircuit(qr)
qc.initialize(desired_vector, [qr[0], qr[1]])

then I build a backend and try to transpile cirquit, create schedule and assemble qobj:

FakeOpenPulse10Q = FakeBackendBuilder("Tashkent", n_qubits=10).build()
backend = FakeOpenPulse10Q()

experiments = transpile(qc, backend=backend)
experiments = schedule(circuits=experiments, backend=backend)
qobj = assemble(experiments, backend=backend)

and everything works but to finish logical sequence for execute I need to run backend.run(qobj).
And here execution fails due to pickle error:

_pickle.PicklingError: Can't pickle <class 'abc.FakeOpenPulse10Q'>: attribute lookup FakeOpenPulse10Q on abc failed

Same thing happens when I try to use FakeOpenPulse2Q (existing) backend. But in case of existing backend it failed due to inaability to pickle local object:

AttributeError: Can't pickle local object 'QobjToInstructionConverter.convert_frame_change.<locals>.gen_fc_sched'

This can be solved (I assume) by using __setstate__ and __getstate__ to manually pickle-unpickle objects.

Anyhow both of this errors occurs in run function, where in FakeBackend we are using FakeJob which uses futures.ProcessPoolExecutor(). And after 15 seconds of googling I noticed that dynamic classes has issue with pickling (which is happening while using process pools).

I think, I can create other FakeJob which will not use pools and use it in generated fake backends run method. 🤔 Maybe it's 2am and I need to sleep a little to came up with better solution 😄

Any suggestions how to overcome this?)

P.S
Is is ok that I always mention your names in PR discussions @taalexander @lcapelluto ? It probably creates a lot of notifications in your accounts. Sorry for that. I can just leave a comments and wait 😄

@taalexander
Copy link
Contributor

It's totally ok to ping me 😄. I was tried to run the sample code

import math

from qiskit import QuantumRegister, QuantumCircuit, transpile, schedule, assemble
from qiskit.test.mock.utils.fake_backend_builder import FakeBackendBuilder

desired_vector = [1 / math.sqrt(2), 0, 0, 1 / math.sqrt(2)]
qr = QuantumRegister(2, "qr")
qc = QuantumCircuit(qr)
qc.initialize(desired_vector, [qr[0], qr[1]])

FakeOpenPulse10Q = FakeBackendBuilder("Tashkent", n_qubits=10).build()
backend = FakeOpenPulse10Q()
experiments = transpile(qc, backend=backend)
experiments = schedule(circuits=experiments, backend=backend)
qobj = assemble(experiments, backend=backend)

but am getting the error

TranspilerError: "The 'layout' must be full (with ancilla)."

If I look at the coupling_map, it includes too many qubits.

>>> backend.configuration().coupling_map
[[0, 4], [1, 2], [2, 3], [2, 6], [3, 4], [4, 8], [5, 6], [6, 7], [6, 10], [7, 8], [8, 12], [9, 10]]

@taalexander
Copy link
Contributor

The backend is missing a parameter rep_times I think.

@taalexander
Copy link
Contributor

taalexander commented Mar 13, 2020

I can, however, recreate your error with

import math

from qiskit import QuantumRegister, QuantumCircuit, transpile, schedule, assemble
from qiskit.test.mock.utils.fake_backend_builder import FakeBackendBuilder
from qiskit.test.mock import FakeOpenPulse2Q

desired_vector = [1 / math.sqrt(2), 0, 0, 1 / math.sqrt(2)]
qr = QuantumRegister(2, "qr")
qc = QuantumCircuit(qr)
qc.initialize(desired_vector, [qr[0], qr[1]])

FakeOpenPulse10Q = FakeBackendBuilder("Tashkent", n_qubits=4, coupling_map=[[0, 1], [1,2], [2,3]]).build()
#backend = FakeOpenPulse2Q()
backend = FakeOpenPulse10Q()
experiments = transpile(qc, backend=backend)
experiments = schedule(circuits=experiments, backend=backend)
qobj = assemble(experiments, backend=backend, rep_time=100)

job = backend.run(qobj)
result = job.result()

Please try again after updating to master of qiskit which has changed this method.

@taalexander
Copy link
Contributor

Did merging in master help?

@IceKhan13
Copy link
Member Author

IceKhan13 commented Mar 18, 2020

Fake job changed. So, no it's using Aer simulator and reads hamiltonian. Now I need to generate Hamiltonian correctly and continue with tests. But all of your comments above correct and it helped :)
I'll get back and ask you again if I'll not be able to run it.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for sticking with this and pushing it through to completion

def setUp(self) -> None:
self.backend = ConfigurableBackend("Tashkent", n_qubits=4)

def test_transpile_schedule_and_assemble(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is partial overlap here with: https://github.com/Qiskit/qiskit-terra/blob/master/test/python/providers/test_fake_backends.py#L51 but this is different enough that it's probably fine. It might be a good follow up to expand this or the other to cover both use cases and deduplicate things a bit.

@jyu00
Copy link
Contributor

jyu00 commented May 6, 2020

@IceKhan13 Can the name be changed to ConfigurableFakeBackend? We may have real configurable backends in the future.

@mergify mergify bot merged commit 51b70a7 into Qiskit:master May 6, 2020
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request May 10, 2020
In Qiskit#3797 tests were incorrectly outside of test/python. This meant that
python unittest discovery did not find or execute these tests because we
set the discovery path to test/python. This commit corrects the
oversight so that we are running these tests. However, one of the
unittests there is dependent on aer being installed so a skip condition
is set on that test so we only attempt to run it if aer installed. But,
that same test is also triggering an aer bug see Qiskit/qiskit-aer#741
so an additional unconditional skip is added until that gets fixed in
aer.
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request May 10, 2020
This commit fixes an issue with the fake configurable backend which was
introduced in Qiskit#3797. Due to an error in how the test files were added
this was not being exersiced by local test runs or CI (this has been
corrected in Qiskit#4424). However, because no tests were being run for this
module it was merged with a broken type for scale. The UchannelLO object
expects a complex input not a list of complex components. This commit
corrects this oversight so that the backends created with this can be
used for pulse simulations and other use cases where the scale parameter
is used. At the same time this renames the class to be a bit more
descriptive to avoid confusion.
@MGLetsoalo
Copy link

Hello, we had a similar project to this one titled: open pulse mock backend for spin based qubits from qiskit camp Africa 2019, the mock qubits where associated with the 13-C nuclear spins coupled to NV centres in a diamond. Based on the computational ability of carbon atoms, it was my believe that these carbon atoms could be used as fake backends that will participate as reactive groups in drug design to combat the covid19 pandemic. If we treat the electron spin as a quantum bus, we can adjust the states that correspond to the syndrome measurements and thus the 13-C nuclear spins provide a platform to design the proper chemistry that will help mitigate the syndrome. There is a lot of research on the development of viral nanoparticles as a template for organising materials at the nano scales and I think that it is time to consolidate these efforts.

@taalexander
Copy link
Contributor

I think it is fine to still have an example backend for an NV center system. Would it be possible to use @IceKhan13's work for this and choose the right parameters? Maybe some slight modifications would be required?

@MGLetsoalo
Copy link

Yes, with 100 qubits we can realise a 100*100 tabular qubit ordering, how do I become part of this discussion so that I may be able to present my attempts?

@taalexander
Copy link
Contributor

If you open up a draft PR with your attempts we can comment directly on it 😄

mergify bot added a commit that referenced this pull request May 18, 2020
In #3797 tests were incorrectly outside of test/python. This meant that
python unittest discovery did not find or execute these tests because we
set the discovery path to test/python. This commit corrects the
oversight so that we are running these tests. However, one of the
unittests there is dependent on aer being installed so a skip condition
is set on that test so we only attempt to run it if aer installed. But,
that same test is also triggering an aer bug see Qiskit/qiskit-aer#741
so an additional unconditional skip is added until that gets fixed in
aer.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this pull request Jul 21, 2020
* Fix U Channel LO property in fake configurable backend

This commit fixes an issue with the fake configurable backend which was
introduced in #3797. Due to an error in how the test files were added
this was not being exersiced by local test runs or CI (this has been
corrected in #4424). However, because no tests were being run for this
module it was merged with a broken type for scale. The UchannelLO object
expects a complex input not a list of complex components. This commit
corrects this oversight so that the backends created with this can be
used for pulse simulations and other use cases where the scale parameter
is used. At the same time this renames the class to be a bit more
descriptive to avoid confusion.

* Fix broken tests

* Fix import in pulse builder tests
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* LargePulseBackendMock: skeleton of backend

* LargePulseBackendMock: fake backend builder works; todo: fix values generation

* FakePulseBackend: fake backend builder generate Almaden like cmap

* FakePulseBackend: defaults initial implementation

* FakePulseBackend: fake backend generation function; move generation to utils package; props generation; TODO: build conf, tests

* FakePulseBackend: move generation function into builder class, parameters documentation, style fixes

* FakePulseBackend: simple testing

* LargePulseBackendMock: build method return FakeBackend, simple tests

* LargePulseBackendMock: hamiltonian generation

* LargePulseBackendMock: test

* LargePulseBackendMock: backend builder configuration + tests

* LargePulseBackendMock: list + fix test; TODO: run test after Aer release

* LargePulseBackendMock: list

* LargePulseBackendMock: list

* LargePulseBackendMock: lint

* LargePulseBackendMock: job run test with released aer

* LargePulseBackendMock: default cmap

* LargePulseBackendMock: linter fixes

* LargePulseBackendMock: release note

* LargePulseBackendMock: release note fix

* LargePulseBackendMock: release note fix

* LargePulseBackendMock: docstring example fix

* Update qiskit/test/mock/utils/fake_backend_builder.py

Co-Authored-By: Lauren Capelluto <[email protected]>

* Update qiskit/test/mock/utils/fake_backend_builder.py

Co-Authored-By: Lauren Capelluto <[email protected]>

* Update releasenotes/notes/large-mock-backend-builder-af0623b43bdcc35e.yaml

Co-Authored-By: Matthew Treinish <[email protected]>

* LargePulseBackendMock: gate length, gate error, coupling map fixes

* LargePulseBackendMock: t1, t2, rerror, frequency as arrays

* LargePulseBackendMock: for some reason liner complains about types

* LargePulseBackendMock: rename to configurable backend, move build to init, fix tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Lauren Capelluto <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
In Qiskit#3797 tests were incorrectly outside of test/python. This meant that
python unittest discovery did not find or execute these tests because we
set the discovery path to test/python. This commit corrects the
oversight so that we are running these tests. However, one of the
unittests there is dependent on aer being installed so a skip condition
is set on that test so we only attempt to run it if aer installed. But,
that same test is also triggering an aer bug see Qiskit/qiskit-aer#741
so an additional unconditional skip is added until that gets fixed in
aer.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@1ucian0 1ucian0 added the mod: pulse Related to the Pulse module label Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants