Git Product home page Git Product logo

Comments (4)

kevinsung avatar kevinsung commented on June 19, 2024 1

@idk3 I made a new issue at #274 to implement the changes discussed here. Do you think that covers everything? If so I think we can close this issue.

from openfermion.

kevinsung avatar kevinsung commented on June 19, 2024
  1. The keys() method of dictionaries actually returns a key view, which is a set-like object. See https://docs.python.org/3/library/stdtypes.html#dict-views.
  2. EDIT: Okay actually I might agree with you. Maybe we should be able to compare and add PolynomialTensors that have different keys.
    However, this does lead me to another question: why is equality comparison here implemented with an __eq__ method, while for SymbolicOperators it is implemented with the isclose method? I don't see a reason to do it differently for both.
  3. TypeError is generally raised to indicate that an operation is not meant to be performed in some way on some objects; it appears to me that this is how it's being used here. The returned error message can contain more specifics about the problem.

from openfermion.

idk3 avatar idk3 commented on June 19, 2024
  1. This is true in Python 3 but not in Python 2, see e.g. https://stackoverflow.com/questions/5629023/key-order-in-python-dictionaries .

  2. This is a fair question in general - I don't have a good solution really. I agree that isclose is a better way to handle things rather than __eq__ at least for the purposes of consistency.

  3. I think you're misinterpreting a point about functions and methods from the docs (I think you might be looking at the second paragraph of https://docs.python.org/3/library/exceptions.html#TypeError ?). The paragraph below clarifies this - "Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError." In this case the arguments would be of the correct type but incorrect value (the dictionaries x.n_body_tensors and y.n_body_tensors have different keys), and a ValueError or similar would be the appropriate error to raise.

from openfermion.

kevinsung avatar kevinsung commented on June 19, 2024
  1. We can handle this by adding the line from builtins import dict and initializing our dictionaries with dict(). I think that's the preferred way to use the future module to handle this compatibility issue.

Three. Okay, I agree that we should raise ValueError in some of these cases then.

from openfermion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.