English
Languages
English
Bengali
Japanese
Spanish

Note

This page was generated from docs/tutorials/09_properties.ipynb.

Properties - or - Operator Factories

Qiskit Nature has various built-in “properties”. These objects are effectively operator factories, since they allow the programming of operator blueprints based on a minimal set of required information. Some commonly used examples are the ParticleNumber, AngularMomentum and Magnetization properties, all of which take only the system size as their only input, and generate a SparseLabelOp of the required size.

These properties can be registered in a problem instance which will cause them to be evaluated once a ground state and/or excited states of that problem have been found. In the following, we will explain the general concept of how this works.

The BaseProblem base class dictates the existence of the .properties attribute on any problem instance. This attribute is of type PropertiesContainer which is an object that can hold at most one instance of any SparseLabelOpsFactory (or property class, as we commonly refer to them).

[1]:
from qiskit_nature.second_q.problems import BaseProblem

dummy_hamiltonian = None

base_problem = BaseProblem(dummy_hamiltonian)
print(base_problem.properties)
<qiskit_nature.second_q.problems.properties_container.PropertiesContainer object at 0x7fa6245829a0>

You can now modify the contents of the PropertiesContainer to your desire:

[2]:
from qiskit_nature.second_q.properties import AngularMomentum

print("AngularMomentum is in problem.properties:", AngularMomentum in base_problem.properties)

print("Adding AngularMomentum to problem.properties...")
base_problem.properties.add(AngularMomentum(2))

print("AngularMomentum is in problem.properties:", AngularMomentum in base_problem.properties)

print("Discarding AngularMomentum from problem.properties...")
base_problem.properties.discard(AngularMomentum)

print("AngularMomentum is in problem.properties:", AngularMomentum in base_problem.properties)
AngularMomentum is in problem.properties: False
Adding AngularMomentum to problem.properties...
AngularMomentum is in problem.properties: True
Discarding AngularMomentum from problem.properties...
AngularMomentum is in problem.properties: False

The specific subclasses of BaseProblem for the various stacks such as electronic structure, vibrational structure or lattice models make things even simpler for you, because they provide direct attributes for the built-in properties of Qiskit Nature:

[3]:
from qiskit_nature.second_q.drivers import PySCFDriver

es_problem = PySCFDriver().run()

print(es_problem.properties.particle_number)
print(es_problem.properties.angular_momentum)
print(es_problem.properties.magnetization)
print(es_problem.properties.electronic_dipole_moment)
print(es_problem.properties.electronic_density)
<qiskit_nature.second_q.properties.particle_number.ParticleNumber object at 0x7fa5d9463310>
<qiskit_nature.second_q.properties.angular_momentum.AngularMomentum object at 0x7fa5d94631f0>
<qiskit_nature.second_q.properties.magnetization.Magnetization object at 0x7fa5d9463250>
<qiskit_nature.second_q.properties.dipole_moment.ElectronicDipoleMoment object at 0x7fa5d9463370>
None
/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/pyscf/dft/libxc.py:772: UserWarning: Since PySCF-2.3, B3LYP (and B3P86) are changed to the VWN-RPA variant, the same to the B3LYP functional in Gaussian and ORCA (issue 1480). To restore the VWN5 definition, you can put the setting "B3LYP_WITH_VWN5 = True" in pyscf_conf.py
  warnings.warn('Since PySCF-2.3, B3LYP (and B3P86) are changed to the VWN-RPA variant, '

Note that the ElectronicDipoleMoment is populated by default. To exclude it, you can use the drivers to_problem() method and provide the include_dipole=False keyword argument. Refer to the drivers documentation for more details.

You can see, that all properties come pre-populated except for the ElectronicDensity. But this is easy to add:

[4]:
from qiskit_nature.second_q.properties import ElectronicDensity

density = ElectronicDensity.from_orbital_occupation(
    es_problem.orbital_occupations,
    es_problem.orbital_occupations_b,
)

es_problem.properties.electronic_density = density

The same concepts apply to the VibrationalStructureProblem and the LatticeModelProblem.

[5]:
import qiskit.tools.jupyter

%qiskit_version_table
%qiskit_copyright

Version Information

SoftwareVersion
qiskitNone
qiskit-terra0.25.1
qiskit_nature0.6.2
System information
Python version3.8.17
Python compilerGCC 11.3.0
Python builddefault, Jun 7 2023 12:29:56
OSLinux
CPUs2
Memory (Gb)6.7694854736328125
Fri Sep 01 17:57:03 2023 UTC

This code is a part of Qiskit

© Copyright IBM 2017, 2023.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.