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

[WIP] QROM demo #1123

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open

[WIP] QROM demo #1123

wants to merge 7 commits into from

Conversation

KetpuntoG
Copy link
Contributor

Before submitting

Please complete the following checklist when submitting a PR:

  • Ensure that your tutorial executes correctly, and conforms to the
    guidelines specified in the README.

  • Remember to do a grammar check of the content you include.

  • All tutorials conform to
    PEP8 standards.
    To auto format files, simply pip install black, and then
    run black -l 100 path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Title:

Summary:

Relevant references:

Possible Drawbacks:

Related GitHub Issues:


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

    Eg. Promote a new PL feature or show a PL implementation of a recent paper.

  • AUDIENCE — Who is this for?

    Eg. Chemistry researchers, PL educators, beginners in quantum computing.

  • KEYWORDS — What words should be included in the marketing post?

  • Which of the following types of documentation is most similar to your file?
    (more details here)

  • Tutorial
  • Demo
  • How-to

@KetpuntoG KetpuntoG changed the title QROM demo [WIP] QROM demo Jun 6, 2024
Copy link

github-actions bot commented Jun 6, 2024

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

@KetpuntoG
Copy link
Contributor Author

[sc-63852]

Copy link

github-actions bot commented Jun 6, 2024

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 1123
  • Deployment SHA: 380a8b17bd382160fc49915f7becc20ef8e8b58b
    (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.

Comment on lines +1 to +11
{
"title": "Intro to QSVT",
"authors": [
{
"id": "guillermo_alonso"
}
],
"dateOfPublication": "2023-05-23T00:00:00+00:00",
"dateOfLastModification": "2024-03-04T00:00:00+00:00",
"categories": [
"Algorithms",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The metadata I usually updated at the end when we already have the thumbnails

Copy link
Contributor

@ixfoduap ixfoduap left a comment

Choose a reason for hiding this comment

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

The overall structure is great, but I think there is a lot of room for improvement in the presentation

Comment on lines +4 to +5
Managing data is a crucial task on any computer, and quantum computers are no exception. Efficient data management is vital in Quantum Machine Learning (QML), search algorithms or state preparation.
In this demonstration, we will introduce the concept of Quantum Read-Only Memory (QROM), a data structure designed to facilitate these tasks.
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
Managing data is a crucial task on any computer, and quantum computers are no exception. Efficient data management is vital in Quantum Machine Learning (QML), search algorithms or state preparation.
In this demonstration, we will introduce the concept of Quantum Read-Only Memory (QROM), a data structure designed to facilitate these tasks.
Managing data is a crucial task on any computer, and quantum computers are no exception. Efficient data management is vital in quantum machine learning, search algorithms, and state preparation.
In this demonstration, we will introduce the concept of a Quantum Read-Only Memory (QROM), a data structure designed to load classical data on a quantum computer.

No need for acronyms (QML) if you are not using them again

Copy link
Contributor

Choose a reason for hiding this comment

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

You should also mention in the introduction that we are going to explain how to implement it using PennyLane

Copy link
Contributor

Choose a reason for hiding this comment

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

In particular, we should probably mention that we have a specific QROM operation that implements it directly, and link to it already at the beginning for easy access

Comment on lines +10 to +11
The QROM is an operator that allows us to load classical data into a quantum computer
associated with indices. This data is represented as a bitstring (list of 0s and 1s) and the operator can be defined as:
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
The QROM is an operator that allows us to load classical data into a quantum computer
associated with indices. This data is represented as a bitstring (list of 0s and 1s) and the operator can be defined as:
The QROM is an operator that allows us to load classical data into a quantum computer. Data is represented as a collection of bitstrings (list of 0s and 1s) that we denote by :math:`b_1, b_2, \ldots, b_N`. The QROM operator is then defined as:

Comment on lines +19 to +23
Suppose our data consists of eight bit-strings :math:`[11, 01, 11, 00, 10, 10, 11, 00]`. Then, the index register will consist of three
qubits (:math:`\log_2 8`) and the target register of two qubits (length of the bit-strings). Following the same example,
:math:`\text{QROM}|010\rangle|00\rangle = |010\rangle|11\rangle`, since the bit-string associated with index :math:`2` is :math:`11`.
We will show three different implementations of this operator: Select, SelectSwap and an extension of the
last one.
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
Suppose our data consists of eight bit-strings :math:`[11, 01, 11, 00, 10, 10, 11, 00]`. Then, the index register will consist of three
qubits (:math:`\log_2 8`) and the target register of two qubits (length of the bit-strings). Following the same example,
:math:`\text{QROM}|010\rangle|00\rangle = |010\rangle|11\rangle`, since the bit-string associated with index :math:`2` is :math:`11`.
We will show three different implementations of this operator: Select, SelectSwap and an extension of the
last one.
For example, suppose our data consists of eight bit-strings, each with two bits: :math:`[11, 01, 11, 00, 10, 10, 11, 00]`. Then, the index register will consist of three
qubits (:math:`3 = \log_2 8`) and the target register of two qubits (length of the bit-strings). In this case, the QROM operator acts as
:math:`\text{QROM}|010\rangle|00\rangle = |010\rangle|11\rangle`, since the bit-string associated with index :math:`2` is :math:`11`.
We will now explain three different implementations of a QROM: Select, SelectSwap, and an extension of SelectSwap.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, here I think it may be better to have a simple dataset of 4 strings of 2 bits, then show the complete action of QROM on all of them. If we pick the first 4 in your example it would be
QROM |00> |00> = |00>|11>
QROM |01> |00> = |01>|01>
QROM |10> |00> = |10>|11>
QROM |11> |00> = |11>|00>

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use one example with 4 bitstrings here, then have another example with 8 bitstrings to be used later throughout


.. math::

\text{Sel}|i\rangle|0\rangle = |i\rangle|\phi_i\rangle,
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
\text{Sel}|i\rangle|0\rangle = |i\rangle|\phi_i\rangle,
\text{Sel}|i\rangle|0\rangle = |i\rangleU_i|0\rangle =|i\rangle|\phi_i\rangle,

Comment on lines +35 to +37
Since the bitstrings can be seen as a particular quantum state, we particularize this operator to the QROM case.
For the following example we are going to use :class:`~.pennylane.BasisEmbedding` as :math:`U_i`, and
the :class:`~.pennylane.Select` template provided by PennyLane.
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
Since the bitstrings can be seen as a particular quantum state, we particularize this operator to the QROM case.
For the following example we are going to use :class:`~.pennylane.BasisEmbedding` as :math:`U_i`, and
the :class:`~.pennylane.Select` template provided by PennyLane.
Since the bitstrings are encoded in computational basis states, we can view QROM as a special case of a Select operator.
For the following example we are going to use :class:`~.pennylane.BasisEmbedding` as :math:`U_i`, and
the :class:`~.pennylane.Select` template provided by PennyLane.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what you mean by "use :class:~.pennylane.BasisEmbedding as :math:U_i". Please clarify in the text.

#
# QROM in PennyLane
# -----------------
# Coding these ideas from scratch can be painful but with the help of PennyLane you can use it in just one line.
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
# Coding these ideas from scratch can be painful but with the help of PennyLane you can use it in just one line.
# Coding a QROM circuit from scratch can be painful, but with the help of PennyLane you can do it in just one line.

# QROM in PennyLane
# -----------------
# Coding these ideas from scratch can be painful but with the help of PennyLane you can use it in just one line.
# We are going to encode the same bitstrings, using the first SelectSwap approach. In this example we use two work wires
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
# We are going to encode the same bitstrings, using the first SelectSwap approach. In this example we use two work wires
# We are going to encode the same bitstrings, using the SelectSwap approach. In this example we use two work wires

return True
return False

@partial(qml.devices.preprocess.decompose, stopping_condition = my_stop, max_expansion=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this @partial?

Comment on lines +168 to +170
qml.PauliX(control_wires[-3])
qml.Hadamard(control_wires[-1])
qml.Hadamard(control_wires[-2])
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this confusing, like you're trying to do too much. I suggest instead creating a more complicated QROM circuit and drawing it to show that it's correct and easy to implement with PL

#
# By implementing various versions of the QROM operator, such as Select and SelectSwap, we optimize quantum circuits
# for enhanced performance and scalability. Numerous studies demonstrate the efficacy of these methods in improving
# State Preparation [#StatePrep]_ techniques by reducing the number of required gates, which I recommend you explore.
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
# State Preparation [#StatePrep]_ techniques by reducing the number of required gates, which I recommend you explore.
# state preparation [#StatePrep]_ techniques by reducing the number of required gates, which we recommend you explore.

Use "we", not "I"

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.

None yet

2 participants