নোট

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

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 0x14bfa1aa5b80>
<qiskit_nature.second_q.properties.angular_momentum.AngularMomentum object at 0x14bfa1aa5a60>
<qiskit_nature.second_q.properties.magnetization.Magnetization object at 0x14bfa1aa5ac0>
<qiskit_nature.second_q.properties.dipole_moment.ElectronicDipoleMoment object at 0x14bfa1aa5f70>
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 qiskit.tools.jupyter

%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
qiskit-terra0.23.0.dev0+fca8db6
qiskit-aer0.11.0
qiskit-ibmq-provider0.19.2
qiskit-nature0.5.0
System information
Python version3.9.14
Python compilerGCC 12.2.1 20220819 (Red Hat 12.2.1-1)
Python buildmain, Sep 7 2022 00:00:00
OSLinux
CPUs8
Memory (Gb)62.501182556152344
Fri Oct 21 16:22:12 2022 CEST

This code is a part of Qiskit

© Copyright IBM 2017, 2022.

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.