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

Contextuality demo #719

Merged
merged 48 commits into from
Sep 1, 2023
Merged

Contextuality demo #719

merged 48 commits into from
Sep 1, 2023

Conversation

josephbowles
Copy link
Contributor

Demo: Contextuality and inductive bias in quantum machine learning

This is a demo for my recent paper https://arxiv.org/abs/2302.01365

In the demo we study the toy learning problem described in the paper, and build and train a quantum model that encodes the relevant inductive bias. The model is shown to outperform a 'generic' quantum model that does not encode this bias.

The demo is not focused much on contextuality (because it would require a lot of explanation), but rather focuses on the type of learning problem (inspired from contextuality) that is presented in the paper.

JAX is used for vectorization and JIT compilation.

@github-actions
Copy link

github-actions bot commented Mar 17, 2023

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 719
  • Deployment SHA: ca82f5619859e648c717109624939207e08c194e
    (The Deployment SHA refers to the latest commit hash the docs were built from)

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Nice demo Joseph! That's a very clear example to work with 😄 Here I leave you a few comments. On the other hand, as the demo is called this way it would be nice if you could define a bit more in depth each of these concepts. A short paragraph to give the idea would be enough


######################################################################
# This demo is based on the article *Contextuality and inductive bias in
# quantum machine learning* [1] by
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to put the links to the biography. Check another demo to see the format. It is usually in the form [#id_bio]

Copy link
Contributor

Choose a reason for hiding this comment

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

"by Joseph Bowles" 😆it is strange that you refer to yourself in the third person, but I imagine that is the correct way to put it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have changed the links. And haha I thought the same about the third person but I find it a bit weird to say 'be me'. I changed the language a bit in this paragraph to use 'we' rather than 'the authors' though.

and thanks for such a thorough review!!

#
# - Describe a specific example of such a problem that is based on the
# well known rock, paper scissors game, and
# - Construct a train a quantum model that is tailored to the symmetries
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# - Construct a train a quantum model that is tailored to the symmetries
# - Construct and train a quantum model that is tailored to the symmetries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have implemented all commit suggestions in the new version.

# `documentation <https://docs.pennylane.ai/en/stable/introduction/interfaces/jax.html>`__.
#

import jax
Copy link
Contributor

Choose a reason for hiding this comment

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

it is better if you do not import the libraries in the introduction. As a general rule we usually import each library in the first cell that makes use of it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok done!



######################################################################
# This demo is based on the article *Contextuality and inductive bias in
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would attract more attention if you reorder this paragraph. Let the first thing the user reads be the question. And then you can say that this is the question that motivates the article and we will work it into the demo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Have rewritten a bit.

# - If two players play different actions, then one player beats the
# other following the usual rule (rock beats scissors, sissors beats
# paper, paper beats rock).
# - If two players play the same action, the one who plays their special
Copy link
Contributor

Choose a reason for hiding this comment

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

reading this I'm not entirely sure I see how to play. Do all 3 players show a value at the same time? or do they go dueling 1 <> 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dueling. Have tried to make it clearer: I say 'The actions of the players are then compared pairwise with the following rules'

ax2.set_yscale("log")
ax2.set_ylabel("Negative log likelihood (train)")
ax2.set_xlabel("training step")

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the output that appears is not intentional, to delete it I think it is enough to write plt.show() at the end of the cell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

# Incorporating knowledge about the data into the model design is
# generally a very good idea!
#
# That is all for this demo. In the paper, it is also shown how models of
Copy link
Contributor

Choose a reason for hiding this comment

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

could you include this paragraph under the heading conclusion?
In the conclusion, although it sounds a bit repetitive, we usually summarize quickly what we have seen in the demo. It is common to say at the end where to learn more. This is the perfect place to comment on what they will find in the paper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, have done that.

#
# References
# ----------
#
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the format of the other demos to be able to link easily to the bio.

:property="og:description": Train a tailored quantum model on a contextuality-inspired dataset
:property="og:image": https://pennylane.ai/qml/_images/contextuality_thumbnail.png

*Author: Joseph Bowles — Posted: 21 March 2023*
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you say that this demo is related to any other demo? Maybe the geometric machine learning demo? It is usually indicated here in the header. Take a look at the header

example:

.. related::
    tutorial_quantum_chemistry Quantum chemistry with PennyLane
    tutorial_vqe A brief overview of VQE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have added the GQML one


######################################################################
# The above game ia an example of a *zero-sum game*: if player 1 beats
# player 2 then necessarily player 2 loses to player 1. This imples
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# player 2 then necessarily player 2 loses to player 1. This imples
# player 2 then necessarily player 2 loses to player 1. This implies

Copy link
Contributor

@ikurecic ikurecic left a comment

Choose a reason for hiding this comment

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

Here are some minor copy editing changes and suggestions. Everything else looks good to me. :)

demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
demonstrations/tutorial_contextuality.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ikurecic ikurecic left a comment

Choose a reason for hiding this comment

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

Hey @josephbowles , here are some minor copy editing changes and suggestions. Everything else looks good to me. :)

@KetpuntoG KetpuntoG requested review from isaacdevlugt and removed request for isaacdevlugt May 4, 2023 17:59
@KetpuntoG
Copy link
Contributor

A problem has been detected with the jax version (it is not a problem of this demo). Next week it will be fixed :)

Copy link
Contributor

@ikurecic ikurecic left a comment

Choose a reason for hiding this comment

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

👌
(Guillermo is on holiday at the moment, but at least I can leave this as a lgtm from my end.)

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

🚀 Really cool topic!

@KetpuntoG KetpuntoG merged commit ff8fb06 into master Sep 1, 2023
8 checks passed
@KetpuntoG KetpuntoG deleted the contextuality_demo branch September 1, 2023 19:41
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.

3 participants