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 0x7f92ccb76640>

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 0x7f92791cb190>
<qiskit_nature.second_q.properties.angular_momentum.AngularMomentum object at 0x7f92791cb340>
<qiskit_nature.second_q.properties.magnetization.Magnetization object at 0x7f92791cb1f0>
<qiskit_nature.second_q.properties.dipole_moment.ElectronicDipoleMoment object at 0x7f92791cb070>
None

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 tutorial_magics

%qiskit_version_table
%qiskit_copyright

Version Information

SoftwareVersion
qiskit1.0.1
qiskit_algorithms0.3.0
qiskit_nature0.7.2
System information
Python version3.8.18
OSLinux
Fri Feb 23 10:25:33 2024 UTC

This code is a part of a Qiskit project

© Copyright IBM 2017, 2024.

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.