question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `qml.FlipSign` subroutine template

See original GitHub issue

Feature details

It would be great to have a FlipSign operator that supports an integer n or its binary representation, such that:

FlipSign(n)|m> = -|m> if m = n FlipSign(n)|m> = |m> if m != n

That is, to change the sign of a specified state. This would facilitate the process of oracle creation

Implementation

Let guess, we have the binary representation bin_n = [1,0,0,0] and wires = range(4) The template could have the following form:

if bin_n[-1] == 0:
     qml.PauliX(wires = wires[-1])

qml.ctrl(qml.PauliZ, control = wires[:-1], control_values = n[:-1])(wires = wires[-1])

if bin_n[-1] == 0:
     qml.PauliX(wires = wires[-1])

We should check that the dimensions of bin_n and wires are the same. Here I leave a subroutine to pass n to list that can be useful 😃


n = 21
wires = range(5)
bin_string = f"{n:b}".zfill(len(wires))
bin_n = [int(i) for i in bin_string]
print(bin_n)

[1,0,1,0,1]

Steps to take

Implementation

  • Create a new subroutine template in the subroutines folder named FlipSign and make it available via qml.FlipSign;
  • Allow qml.FlipSign to appear in the relevant parts of the documentation.

See other subroutine templates from the above-linked folder for the details of the implementation and documentation

Testing

Add tests to a new test file to the templates/test_subroutines/ folder. The testing should follow similar to the testing of other subroutines.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

Final example


@qml.qnode(dev)
def circuit():
   qml.Hadamard(wires = 0)
   qml.FlipSign(1, wires = 0)
   qml.Hadamard(wires = 0)
   return qml.sample()

circuit()
[1]

|0> --> |0> + |1> --> |0> - |1> --> |1>

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
KetpuntoGcommented, Jul 11, 2022

Yes! Closed 🚀

2reactions
sergiomtzlosacommented, Jun 20, 2022

Hi @KetpuntoG ,

No problem at all!!! I keep working on it.💪

Thanks for the pinpoint path!

[EDIT] Finally here is my file but I think that I have do not understand properly your indications, I think I misunderstood something or I missed something though🤦

Besides this, I still do not understand the test class, can I have some hint about what to do there? Anyway, I am still digging into the code…

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing QML Extensions with C++ - Qt Documentation
You can write extensions to add your own QML types, extend existing Qt types, ... We create a new project using the Qt...
Read more >
Templates — PennyLane 0.28.0 documentation
The layer function creates a new template by repeatedly applying a sequence of quantum gates to a set of wires. You can import...
Read more >
pennylane/templates.rst at master - GitHub
The layer function creates a new template by repeatedly applying a sequence of quantum gates to a set of wires. You can import...
Read more >
Qt quick project - how to invoke cpp function in qml file?
And with setContextProperty you can ad global QML types via cpp. ... So like in the example above, it should be possible to...
Read more >
pennylane Changelog - pyup.io
The `qml.map_wires()` function requires a dictionary representing a wire map. Use it with ... The example of the `qml.FlipSign` template has been updated....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found