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

Migrate QGAN tutorial to SamplerQNN #555

Merged
merged 33 commits into from
Feb 24, 2023

Conversation

adekusar-drl
Copy link
Collaborator

@adekusar-drl adekusar-drl commented Jan 25, 2023

Summary

The tutorial is updated to make use of SamplerQNN. The content of the tutorial has been heavily revised.

@adekusar-drl adekusar-drl added this to the 0.6.0 milestone Jan 25, 2023
@adekusar-drl adekusar-drl removed this from the 0.6.0 milestone Feb 8, 2023
@adekusar-drl adekusar-drl changed the title [WIP] Migrate QGAN tutorial to SamplingQNN [WIP] Migrate QGAN tutorial to SamplerQNN Feb 13, 2023
@adekusar-drl adekusar-drl changed the title [WIP] Migrate QGAN tutorial to SamplerQNN Migrate QGAN tutorial to SamplerQNN Feb 13, 2023
@adekusar-drl adekusar-drl marked this pull request as ready for review February 13, 2023 11:50
@adekusar-drl
Copy link
Collaborator Author

@ElePT for your attention as an expert in the tutorials :)

@adekusar-drl adekusar-drl requested a review from ElePT February 13, 2023 11:50
@coveralls
Copy link

coveralls commented Feb 13, 2023

Pull Request Test Coverage Report for Build 4264056896

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 90.892%

Totals Coverage Status
Change from base Build 4223179046: 0.0%
Covered Lines: 3423
Relevant Lines: 3766

💛 - Coveralls

Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for the hard work refactoring this tutorial. Overall it looks really good. I left some minor comments on the section numbering, a few code suggestions (one regarding primitive syntax), and a few suggestions for the wording that I hope make sense.

"## Tutorial\n",
"\n",
"### Data and Representation\n",
"## 2. Data and Representation\n",
"\n",
"First, we need to load our training data $X$.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I cannot add a suggestion directly but in the line below, but would it make sense to say "In this tutorial, the training data is given by a 2D multivariate normal distribution"???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Totally makes sense, replaced, thanks!

@adekusar-drl adekusar-drl added this to the 0.6.0 milestone Feb 23, 2023
@adekusar-drl
Copy link
Collaborator Author

@woodsp-ibm would be nice to have your review as usual ;)

@@ -79,8 +87,8 @@
"import torch\n",
"from qiskit.utils import algorithm_globals\n",
"\n",
"torch.manual_seed(42)\n",
"algorithm_globals.random_seed = 42"
"algorithm_globals.random_seed = 123456\n",
Copy link
Member

Choose a reason for hiding this comment

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

Above it states this

We first begin by fixing seeds in the random number generators, then we will...

I assume people by now would realize that this just for reproducibility of the outcome in this tutorial, and for no other reason. Would it harm to to state that ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No harm at all, added.

"\n",
"The qGAN \\[1\\] is a hybrid quantum-classical algorithm used for generative modeling tasks. The algorithm uses the interplay of a quantum generator $G_{\\theta}$, i.e., an ansatz, and a classical discriminator $D_{\\phi}$, a neural network, to learn the underlying probability distribution given training data.\n",
"\n",
"The generator and discriminator are trained in alternating optimization steps, where the generator aims at generating samples that will be classified by the discriminator as training data samples (i.e, samples extracted from the real training distribution), and the discriminator tries to differentiate between original training data samples and data samples from the generator (in other words, telling apart the real and generated distributions). The final goal is for the quantum generator to learn a representation for the training data's underlying probability distribution.\n",
"The generator and discriminator are trained in alternating optimization steps, where the generator aims at generating probabilities that will be classified by the discriminator as training data values (i.e, probabilities from the real training distribution), and the discriminator tries to differentiate between original distribution and probabilities from the generator (in other words, telling apart the real and generated distributions). The final goal is for the quantum generator to learn a representation for the target probability distribution.\n",
Copy link
Member

Choose a reason for hiding this comment

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

This is a really minor comment to some unchanged text above

of a quantum generator G, i.e., an ansatz, and a classical discriminator$D, a neural network

The generator has an i.e. (i.e. an ansatz) whereas discriminator just says, a neural network.

Was thinking about this below as it also explains ansatz a little (though it goes into things later in the notebook).

of a quantum generator G, an ansatz (parametrized quantum circuit), and a classical discriminator$D, a neural network

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added "(parametrized quantum circuit)"

@@ -237,7 +182,17 @@
}
},
"source": [
"We move to PyTorch modeling and start from converting data arrays into tensors and create a data loader from our training data."
"## 3. Definitions of the Neural Networks\n",
"In this section we define two neural networks as described above:\n",
Copy link
Member

Choose a reason for hiding this comment

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

Above it described the generator as an ansatz (I am thinking the very minor comment I made about it saying quantum generator, i,e, an ansatz - do people think of that as a neural network?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Slightly rephrased the sentences.

@woodsp-ibm
Copy link
Member

The issue seems to be multinominal is mispelled - its not multinomial as you want (has an extra n in it). Maybe mutinomial is not needed in the custom dict though it does no harm there.

@adekusar-drl
Copy link
Collaborator Author

The issue seems to be multinominal is mispelled - its not multinomial as you want (has an extra n in it). Maybe mutinomial is not needed in the custom dict though it does no harm there.

Ah, shame on me, I don't see typos! I thought I typed correctly, but the word is not in the dictionary.

@adekusar-drl adekusar-drl merged commit 9b1c56e into qiskit-community:main Feb 24, 2023
@adekusar-drl adekusar-drl deleted the migrate_qgan2 branch February 24, 2023 18:19
oscar-wallis pushed a commit that referenced this pull request Feb 16, 2024
* updated tutorial

* new training technique

* fix spelling

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: ElePT <[email protected]>

* code review

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* code review

* fix spell

* Update docs/tutorials/04_torch_qgan.ipynb

Co-authored-by: Steve Wood <[email protected]>

* revert dictionary

* update dictionary

---------

Co-authored-by: ElePT <[email protected]>
Co-authored-by: Steve Wood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants