GithubHelp home page GithubHelp logo

Comments (12)

idk3 avatar idk3 commented on July 2, 2024 6

@kevinsung I'm late to the party, but one solution when all else fails is to import within the function. It looks like you've found a better solution through restructuring :)

from openfermion.

babbush avatar babbush commented on July 2, 2024 1

Great. Write "Fixes #94" in that PR so that when we merge it will close this issue automatically.

from openfermion.

babbush avatar babbush commented on July 2, 2024

These sorts of circular dependancies can be really annoying to deal with. You may need to change the order of imports in __init__ somewhere (breaking the alphabetical order) or you may need to do a much more specific import somewhere that does the import just inside a function instead of at the top of the file. In this sort of situation, I recommend just hacking to try to make things work. I do not think there is a nice general strategy to avoid this.

@Strilanc @maffoo @Spaceenter do you guys have any more enlightened software engineering tips for avoiding this sort of thing? @idk3 I know you dealt with this a lot in FermiLib. Any ideas?

from openfermion.

Spaceenter avatar Spaceenter commented on July 2, 2024

My past experience is that circular dependencies indicate design issues, and could usually be solved by a bit re-design.
For this case, it seems like 'util' should be the lowest level. I agree things like "swap_column" and "swap_rows" should belong to 'util'. But I feel trotter_error.py should probably belong to higher level, maybe even higher than Hamiltonion.

I think the layer should be util -> ops -> hamiltonion -> high-level "util" such as the trotter_error thing.

@idk3 @babbush - WDYT?

from openfermion.

Strilanc avatar Strilanc commented on July 2, 2024

I agree with @Spaceenter

from openfermion.

babbush avatar babbush commented on July 2, 2024

from openfermion.

kevinsung avatar kevinsung commented on July 2, 2024

In that case one solution is to move swap_rows and swap_columns to ops/_quadratic_hamiltonian.py and import these functions in utils/_slater_determinants.py.

from openfermion.

babbush avatar babbush commented on July 2, 2024

from openfermion.

kevinsung avatar kevinsung commented on July 2, 2024

However, I realized that in my pull request, I import other things from utils in ops/_quadratic_hamiltonian.py.

from openfermion.

kevinsung avatar kevinsung commented on July 2, 2024

Namely, I need to use givens_decomposition and fermionic_gaussian_decomposition from utils/_slater_determinants.py in ops/_quadratic_hamiltonian.py.

from openfermion.

kevinsung avatar kevinsung commented on July 2, 2024

Perhaps utils/_slater_determinants.py needs a new home.

from openfermion.

kevinsung avatar kevinsung commented on July 2, 2024

Okay, I think I have a satisfactory solution. I will restructure the code to resolve this in PR #95 .

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.