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

[BugFix] KeyError when running QNode(qfun, dev)(graph) with graph an instance of networkx Graph object #6600

Merged
merged 11 commits into from
Nov 20, 2024

Conversation

PietropaoloFrisoni
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni commented Nov 19, 2024

Context: Issue #6585 indicates that we don't currently allow arguments with types defined in libraries not listed in the supported interfaces.

In #6225, the convention of treating internally as interface=None parameters of the numpy interface has been introduced.
The idea of this PR is to allow non-trainable qnode inputs to "just work" as arguments, without any special consideration or treatment. We want to rely on the default numpy interface for libraries we know nothing about.

Description of the Change: By default, we set None as the value of the interface if the latter is not found in the list of supported interfaces. According to the convention introduced in #6225, this should automatically map the interface to numpy.

Benefits: Now the qnode accepts arguments with types defined in libraries that are not necessarily in the list of supported interfaces, such as the Graph class defined in networkx.

Possible Drawbacks: None that I can think of.

Related GitHub Issues: #6585

Related Shortcut Stories: [sc-78344]

Copy link
Contributor

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.

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review November 19, 2024 15:28
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.45%. Comparing base (c9af833) to head (691964d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6600   +/-   ##
=======================================
  Coverage   99.45%   99.45%           
=======================================
  Files         450      450           
  Lines       42088    42088           
=======================================
  Hits        41857    41857           
  Misses        231      231           

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


🚨 Try these New Features:

Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

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

Looks harmless enough 🤞🏻

@PietropaoloFrisoni PietropaoloFrisoni enabled auto-merge (squash) November 20, 2024 16:51
@PietropaoloFrisoni PietropaoloFrisoni merged commit eb37a95 into master Nov 20, 2024
46 checks passed
@PietropaoloFrisoni PietropaoloFrisoni deleted the Bugfix_key_error_networkx branch November 20, 2024 16:51
astralcai pushed a commit that referenced this pull request Nov 20, 2024
… an instance of `networkx` Graph object (#6600)

**Context:** Issue #6585 indicates that we don't currently allow
arguments with types defined in libraries not listed in the supported
interfaces.

In #6225, the convention of treating internally as `interface=None`
parameters of the `numpy` interface has been introduced.
The idea of this PR is to allow non-trainable `qnode` inputs to "just
work" as arguments, without any special consideration or treatment. We
want to rely on the default `numpy` interface for libraries we know
nothing about.

**Description of the Change:** By default, we set `None` as the value of
the interface if the latter is not found in the list of supported
interfaces. According to the convention introduced in #6225, this should
automatically map the interface to `numpy`.

**Benefits:** Now the `qnode` accepts arguments with types defined in
libraries that are not necessarily in the list of supported interfaces,
such as the `Graph` class defined in `networkx`.

**Possible Drawbacks:** None that I can think of.

**Related GitHub Issues:** #6585 

**Related Shortcut Stories:** [sc-78344]

---------

Co-authored-by: Christina Lee <[email protected]>
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.

4 participants