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

Adds documentation for the default_filter_criterion #726

Merged

Conversation

Anthony-Gandon
Copy link
Contributor

@Anthony-Gandon Anthony-Gandon commented Jun 29, 2022

Fix #643

Summary

Adds a note in the docstring of the default_filter_criterion() method to explicit that it is assuming singlet spin configuration.
An exemple of how a custom filter could be given for other configurations is also provided (it is only an attempt because I don't yet know how to ensure that the AngularMomentum property exists)

Details and comments

def custom_filter_criterion(problem):
      def filter_criterion(problem, eigenstate, eigenvalue, aux_values):
          try:
              num_particles_aux = aux_values["ParticleNumber"][0]
              total_angular_momentum_aux = aux_values["AngularMomentum"][0]
          except TypeError:
              num_particles_aux = aux_values[0][0]
              total_angular_momentum_aux = aux_values[1][0]
          particle_number = cast(
              ParticleNumber,
              problem.grouped_property_transformed.get_property(ParticleNumber),
          )
          total_angular_momentum = cast(
              AngularMomentum,
              problem.grouped_property_transformed.get_property(AngularMomentum),
          )
          return np.isclose(
              total_angular_momentum.spin, total_angular_momentum_aux
          ) and np.isclose(
              particle_number.num_alpha + particle_number.num_beta, num_particles_aux
          )

      return partial(filter_criterion, problem)

At the moment and with a simple setup for the problem, I'm getting None when trying to access the AngularMomentum property.

qubit_op = QubitConverter(mapper=JordanWignerMapper(),
                                               two_qubit_reduction=False,
                                               z2symmetry_reduction=None)
driver = PySCFDriver(atom="H .0 .0 .0; H .0 .0 0.75",
                     unit=UnitsType.ANGSTROM,
                     charge=0,
                     spin=0,
                     basis="sto3g")
esp = ElectronicStructureProblem(driver)
new_numpy_solver = NumPyEigensolverFactory(filter_criterion=custom_filter_criterion(esp))
new_numpy_excited_states_calculation = ExcitedStatesEigensolver(qubit_op, new_numpy_solver)

How could I setup a working test for this?

@HuangJunye HuangJunye added the Community PR PRs from contributors that are not 'members' of the Qiskit organization label Jun 30, 2022
@mrossinek mrossinek removed the Community PR PRs from contributors that are not 'members' of the Qiskit organization label Jul 4, 2022
@coveralls
Copy link

coveralls commented Jul 4, 2022

Pull Request Test Coverage Report for Build 2801582482

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.666%

Totals Coverage Status
Change from base Build 2799719849: 0.0%
Covered Lines: 17081
Relevant Lines: 19939

💛 - Coveralls

@woodsp-ibm
Copy link
Member

We will have to ensure this gets this into the relocated classes too from the refactor of #722

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

As previously mentioned by Steve, we have restructured the code base, meaning that this change now needs to be applied to the class located at qiskit_nature/second_q/problems and needs to leave the old code unchanged. A matching test location exists, too.

Other than that, this PR looks good to me 👍

mrossinek
mrossinek previously approved these changes Jul 19, 2022
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Thanks, @Anthony-Gandon!

mrossinek
mrossinek previously approved these changes Jul 19, 2022
mrossinek
mrossinek previously approved these changes Jul 21, 2022
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Other than this, this LGTM 👍

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Thanks, Anthony!

@mergify mergify bot merged commit efab7e0 into qiskit-community:main Aug 5, 2022
@Anthony-Gandon Anthony-Gandon deleted the document_filter_criterion branch May 24, 2023 15:50
Anthony-Gandon added a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
…#726)

* Adds documentation for the default_filter_criterion to explicit the singlet spin configuration assumption.

* Fixes the documentation.

* Fixes some checks.

* Fixes style.

* Moves the docstring from the method get_default_filter_criterion to the class docstring.
Changes the test for custom filters to a more relevant example with the doublets of BeH

* Changes are now applied to the class located at qiskit_nature/second_q/problems

* Fixes the test

* Fixes the test

* Fixes the test

* Updates documentation the test

* Retests after coverall issue

* Retest after coverall issue

* Fix indenting of the docstring

* Update qiskit_nature/second_q/problems/electronic_structure_problem.py

Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Max Rossmannek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ElectronicStructureProblem.get_default_filter_criterion assumes singlet spin
5 participants