Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Add SklearnIQDiscriminator. #316

Merged
merged 8 commits into from
Jan 2, 2020
Merged

Conversation

hodgestar
Copy link
Contributor

@hodgestar hodgestar commented Dec 13, 2019

Summary

This PR adds a new measurement IQ discriminator that accepts any sklearn classifier as an input and uses that classifier to categorize measurements.

Details and comments

This is my first qiskit PR, so feedback welcome!

I couldn't find where the measurement docs should live. If someone lets me know where to start some, I can add them as part of this PR.

@claassistantio
Copy link

claassistantio commented Dec 13, 2019

CLA assistant check
All committers have signed the CLA.

@claassistantio
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@dcmckayibm dcmckayibm requested a review from eggerdj December 13, 2019 16:15
Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution. This is looking very good.
On top of the requested changes, could you also add the following to the example notebook (it is in qiskit-ignis/examples/DiscriminatorTutorial.ipynb) to highlight your work?

from sklearn.svm import SVC

svcs = {
    0: SVC(C=1., kernel="rbf", gamma="scale"),
    1: SVC(C=1., kernel="rbf", gamma="scale")
}

svc_discriminators = {}

for q in qubits:
    svc_discriminators[q] = SklearnIQDiscriminator(svcs[q], result, [q], ['0', '1'])
    
fig, ax = plt.subplots(1, 2, figsize=(14,5))

svc_discriminators[0].plot(ax[0], flag_misclassified=True, show_boundary=True)
svc_discriminators[1].plot(ax[1], flag_misclassified=False, show_boundary=True);

I suggest adding this at the end of the section entitled Single-qubit discriminator

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

Made a suggestion to make is more transparent to the user what we require from the classifier instance.

@hodgestar
Copy link
Contributor Author

@eggerdj Thanks for the review! I've added the section to the tutorial notebook, but I don't think I have pulse-level access to any multi-qubit machine, so I'm unsure how to run the notebook cleanly and generate new output. Any suggestions?

@hodgestar
Copy link
Contributor Author

I think all comments have been addressed and that this is ready for further review.

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

@hodgestar This looks good. A few minor details: lint checks are failing.
Regarding the IQ data: there is a pickled data set test_result.pickle in the example folder which contains data from one of the IBM Q backends. You can directly load this without having to interact with the backend by running the cell with

if use_prerun_data:
    #Use pickle to load existing data
    import pickle
    from qiskit.result import Result

    with open('test_result.pickle', 'rb') as handle:
        res = pickle.load(handle)

    result = Result.from_dict(res)
else:
    result = job.result(timeout=3600)

This will allow you to test all sorts of classifiers.

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

Code looks good but style checks are failing (see https://travis-ci.com/Qiskit/qiskit-ignis/jobs/267623281). Please see suggestions below.

test/measurement/discriminator/test_iq_discriminator.py Outdated Show resolved Hide resolved
test/measurement/discriminator/test_iq_discriminator.py Outdated Show resolved Hide resolved
@hodgestar
Copy link
Contributor Author

Linting issues fixed (passing locally, waiting for Travis to finish). I updated the discriminator tutorial output.

Note: Updating the notebook isn't quite trivial because even with use_prerun_data the it requires a suitable quantum computer backend (it tries to set up operations on qubits 0 & 1, tries to measure qubits 0-19, uses the pulse backend, etc). Rather than heavily edit the notebook in this PR, I fudged things by skipping the code blocks that set up the schedule and manually fixing the execution count afterwards to make the notebook look nice.

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks a lot for this, really cool stuff.

@eggerdj
Copy link
Contributor

eggerdj commented Dec 17, 2019

@hodgestar You actually don't need to run the schedules or define them. If you just want to play with the pickled data you need to run only the imports, this block:

qubits = [0, 1]
schedules = []
meas_buffer = 2
shots = 512
experiment_name = 'X90p'

and the data loading part. Then you can create discriminators.

@eggerdj
Copy link
Contributor

eggerdj commented Dec 17, 2019

@dcmckayibm This looks good. I am happy to merge this.

@hodgestar
Copy link
Contributor Author

@eggerdj Re notebook: Yep, that's what I did, but it's nice to be able to just restart & run all so that one has confidence the notebook runs correctly end to end. Anyway, it's good for now I think. Thanks for reviewing!

@hodgestar
Copy link
Contributor Author

@eggerdj @dcmckayibm Re-pinging this -- and happy new year!

@dcmckayibm dcmckayibm merged commit ce9d385 into qiskit-community:master Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants