Skip to content

Conversation

@KetpuntoG
Copy link
Contributor

@KetpuntoG KetpuntoG commented Oct 2, 2024

To do:

  • [] Final review
  • Add thumbnail
  • Add changeling

In this PR we add qml.OutPoly. An operator that allows to apply arbitrary polynomials on quantum registers.

Example where we want to create the operator:
$$U|x\rangle |y\rangle |0\rangle = |x\rangle |y\rangle |x^2 + y\rangle$$

import pennylane as qml

x_wires = [0, 1, 2]
y_wires = [3, 4, 5]

output_wires = [6, 7, 8]


def f(x, y):
    return x ** 2 + y


@qml.qnode(qml.device("default.qubit", shots = 1))
def circuit():
    # loading values for x and y
    qml.BasisEmbedding(2, wires=x_wires)
    qml.BasisEmbedding(2 , wires=y_wires)

    # applying the polynomial
    qml.OutPoly(f,
                input_registers = [x_wires, y_wires],
                output_wires=output_wires)

    return qml.sample(wires=output_wires)

print(circuit())

Context:
This operator is born of the quantum arithmetic project

Benefits:

complete flexibility for the user to create new arithmetic operators

[sc-72629]

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2024

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.
@KetpuntoG
Copy link
Contributor Author

@codecov
Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.38%. Comparing base (43cb979) to head (170c273).
Report is 321 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6320      +/-   ##
==========================================
- Coverage   99.38%   99.38%   -0.01%     
==========================================
  Files         450      452       +2     
  Lines       42619    42771     +152     
==========================================
+ Hits        42359    42509     +150     
- Misses        260      262       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@willjmax willjmax 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 initial comments. I will look over the Mobius transformation in my next review.

Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Leaving some initial comments, will take a closer look at the decomposition next.

[skip ci]

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Thanks @KetpuntoG, overall looks good!

Copy link
Contributor

@willjmax willjmax 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!

[skip ci]

Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Thanks @KetpuntoG, some more suggestion regarding docs; after which it should be 🚀

obliviateandsurrender

This comment was marked as duplicate.

@KetpuntoG KetpuntoG enabled auto-merge (squash) October 25, 2024 18:16
@KetpuntoG KetpuntoG merged commit 4986a3a into master Oct 25, 2024
40 checks passed
@KetpuntoG KetpuntoG deleted the qml_outpoly branch October 25, 2024 18:50
mudit2812 pushed a commit that referenced this pull request Nov 11, 2024
To do:
- [x] Final review
- [x] Add thumbnail
- [x] Add changeling

In this PR we add `qml.OutPoly`. An operator that allows to apply
arbitrary polynomials on quantum registers.

Example where we want to create the operator:
$$U|x\rangle |y\rangle |0\rangle = |x\rangle |y\rangle |x^2 + y\rangle$$

```python

import pennylane as qml

x_wires = [0, 1, 2]
y_wires = [3, 4, 5]

output_wires = [6, 7, 8]


def f(x, y):
    return x ** 2 + y


@qml.qnode(qml.device("default.qubit", shots = 1))
def circuit():
    # loading values for x and y
    qml.BasisEmbedding(2, wires=x_wires)
    qml.BasisEmbedding(2 , wires=y_wires)

    # applying the polynomial
    qml.OutPoly(f,
                input_registers = [x_wires, y_wires],
                output_wires=output_wires)

    return qml.sample(wires=output_wires)

print(circuit())

```

**Context:**
This operator is born of the quantum arithmetic project 


**Benefits:**

complete flexibility for the user to create new arithmetic operators


[[sc-72629](https://app.shortcut.com/xanaduai/story/72629/support-polynomial-arithmetic)]

---------

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
Co-authored-by: Will <wmaxwell90@gmail.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants