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.

[BUG] QubitStateVector is decomposed even on devices that support it

See original GitHub issue

Expected behavior

QubitStateVector should not be decomposed and the output should be:

 0: ──╭QubitStateVector(M0)──╭┤ State 
 1: ──╰QubitStateVector(M0)──╰┤ State 
M0 =
[1. 0. 0. 0.]

This happens up to 0.19.1

Actual behavior

QubitStateVector is decomposed

 0: ──╭C──╭C──╭┤ State 
 1: ──╰X──╰X──╰┤ State 

This happens in 0.20.0 an beyond.

Additional information

No response

Source code

import pennylane as qml
from pennylane.devices import DefaultQubit
from pennylane import numpy as np

dev = qml.device('default.qubit', wires=2)

@qml.qnode(dev, diff_method='parameter-shift')
def circuit():
    qml.QubitStateVector(np.array([1.0, 0.0, 0.0, 0.0]), wires=[0, 1])
    return qml.state()

assert 'QubitStateVector' in dev.operations
print(qml.draw(circuit)())

Tracebacks

No response

System information

As stated above the problem starts with 0.20.0.

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
josh146commented, Feb 2, 2022

Yeah, that was my idea at the time. It ended up failing because if you call the gradient decompositions inside the gradient logic, you can enter a case where classical processing occurs, which can’t be tracked by the autodiff framework; so you end up with the incorrect gradients being returned.

E.g., if you have a decomposition that looks like

Gate1(x) -> [Gate2(x^2), Gate3(sin(x))]

— that is, a quantum gate is decomposed down to quantum + classical components — the parameter-shift rule would only give the quantum component of the gradient, the classical component is lost.

I tried several workarounds, one being manually tracking the classical component of the decomposition, and returning class_jac @ quantum_jac, but this ended up adding a lot of complexity and overhead 🤔 I also couldn’t get it to work for all edge cases at the time, if I recall.

Moving the gradient-based decomposition higher up the stack, where the autodiff frameworks can continue to track classical processing, solves this, with the disadvantage being as we discussed above.

But this is definitely something we would love to support; being able to compute hybrid Jacobians without relying on the autodiff frameworks would solve this.

0reactions
cvjjmcommented, Feb 2, 2022

I see. But couldn’t the decomposition be done in the jacobian method of the respective tapes in a way that works for each interface?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: QubitStateVector function for qubit state preparation ...
Hi, There is some bug or inconsistency in this function. see the file jupyter notebook attached. dev2 = qml.device('default.qubit', ...
Read more >
Data encoding on forest.qvm - PennyLane Help
Hi @josh is there any alternative for the above problem. I am planning to handle lots of data on a quantum circuit and...
Read more >
Demonstration of quantum volume 64 on a ... - IOPscience
Decomposition in the natural gate direction: while the device software is easily capable of implementing a CX gate in both directions, in reality...
Read more >
Efficient Decomposition of Unitary Matrices in Quantum Circuit ...
Unitary decomposition is a widely used method to map quantum algorithms to an arbitrary set of quantum gates. Efficient implementation of this decomposition...
Read more >
arXiv:2212.01077v1 [quant-ph] 2 Dec 2022
In this work, we use a measurement based on error amplification to characterize and correct the small single-qubit rotation errors originating ...
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