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

[BUG] Inconsistent qnode return behavior for list and tuple #6540

Closed
1 task done
albi3ro opened this issue Nov 6, 2024 · 1 comment · Fixed by #6568
Closed
1 task done

[BUG] Inconsistent qnode return behavior for list and tuple #6540

albi3ro opened this issue Nov 6, 2024 · 1 comment · Fixed by #6568
Labels
bug 🐛 Something isn't working

Comments

@albi3ro
Copy link
Contributor

albi3ro commented Nov 6, 2024

Expected behavior

I would expect identical behavior for both lists or tuples.

Actual behavior

If we return a measurement process in a list, we add back in a dimension. But if the measurement process is in a tuple, we do not add a tuple dimension back in.

Additional information

No response

Source code

@qml.qnode(qml.device('default.qubit'))
def circuit(t):
    return t([qml.expval(qml.Z(0))])
>>> circuit(tuple)
1.0
>>> circuit(list)
[1.0]

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@albi3ro albi3ro added the bug 🐛 Something isn't working label Nov 6, 2024
andrijapau added a commit that referenced this issue Nov 21, 2024
**Context:**

The output of QNode execution was not consistent based on the type of
the qfunc output,
```python
@qml.qnode(qml.device('default.qubit'))
def circuit(t):
    return t([qml.expval(qml.Z(0))])
>>> circuit(tuple)
1.0
>>> circuit(list)
[1.0]
```

**Description of the Change:**

Updates how the results of the QNode execution gets "type-converted"
according to the `qfunc_output`.

After this fix we get consistency,
```python
@qml.qnode(qml.device('default.qubit'))
def circuit(t):
    return t([qml.expval(qml.Z(0))])
>>> circuit(tuple)
(1.0,)
>>> circuit(list)
[1.0]
```

**Benefits:** Consistency

**Possible Drawbacks:** Output of QNode execution may look different
than people are used to. A direct example is needed to change some tests
to squeeze out the new dimension that has been introduced.

**Related GitHub Issue:** #6540 

[sc-77682]
@andrijapau
Copy link
Contributor

Fixed in #6568. 😄 Forgot to add the "Fixes" key word for automatic closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants