Note

This page was generated from docs/tutorials/08_qcschema.ipynb.

QCSchema#

The QCSchema is a standard data format for quantum chemistry. The current version of it which has been adopted by multiple classical chemistry codes, only supports serialization via JSON, but their docs clearly indicate that HDF5 may also be used. Thus, in Qiskit Nature, we have opted for implementing support for both hierarchical data formats.

Now, why do we have a tutorial specifically about this format you may wonder? The reason is fairly simple: this is the data format which our drivers use internally to transfer data between the classical computation and Qiskit Nature. Thus, this tutorial will explain a few concepts, in case you want to get a bit more elaborate with your driver interaction.

Note: the support for electronic-repulsion integrals as part of the QCSchema is not yet part of the official specification and, thus, custom to Qiskit Nature. But we are working with the QCSchema authors to make this integration official!

For the purposes of this tutorial, we are using the PySCFDriver, but most discussion points should apply to the other electronic structure drivers, too.

First, let us construct a PySCFDriver and run it:

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

driver = PySCFDriver()

problem = driver.run()
print(problem)
<qiskit_nature.second_q.problems.electronic_structure_problem.ElectronicStructureProblem object at 0x7fa68be7b580>

This is basically short for the following:

[2]:
from qiskit_nature.second_q.problems import ElectronicBasis

driver.run_pyscf()
problem = driver.to_problem(basis=ElectronicBasis.MO, include_dipole=True)
print(problem.basis)
ElectronicBasis.MO

There are two things to note here: - the problem is specifically requested in the MO basis - dipole integrals are handled separately (because the current QCSchema standard does not support these coefficients)

What this means for you as an end-user, is that you can also request the problem in another basis like so:

[3]:
ao_problem = driver.to_problem(basis=ElectronicBasis.AO)
print(ao_problem.basis)
The provided alpha-beta overlap matrix is NOT unitary! This can happen when the alpha- and beta-spin orbitals do not span the same space. To provide an example of what this means, consider an active space chosen from unrestricted-spin orbitals. Computing <S^2> within this active space may not result in the same <S^2> value as obtained on the single-reference starting point. More importantly, this implies that the inactive subspace will account for the difference between these two <S^2> values, possibly resulting in significant spin contamination in both subspaces. You should verify whether this is intentional/acceptable or whether your choice of active space can be improved. As a reference, here is the summed-absolute deviation of `S^T @ S` from the identity: 7.064215023495638
ElectronicBasis.AO

If you now want to transform an AO problem into the MO basis, you need to use the BasisTransformer which is explained in a separate tutorial.

This is the point, where you need to understand that the to_problem method actually relies on the to_qcschema method internally:

[4]:
from qiskit_nature.second_q.formats.qcschema_translator import qcschema_to_problem

qcschema = driver.to_qcschema()
ao_problem = qcschema_to_problem(qcschema, basis=ElectronicBasis.AO)
The provided alpha-beta overlap matrix is NOT unitary! This can happen when the alpha- and beta-spin orbitals do not span the same space. To provide an example of what this means, consider an active space chosen from unrestricted-spin orbitals. Computing <S^2> within this active space may not result in the same <S^2> value as obtained on the single-reference starting point. More importantly, this implies that the inactive subspace will account for the difference between these two <S^2> values, possibly resulting in significant spin contamination in both subspaces. You should verify whether this is intentional/acceptable or whether your choice of active space can be improved. As a reference, here is the summed-absolute deviation of `S^T @ S` from the identity: 7.064215023495638

Specifically extracting the QCSchema object from the driver allows you to later extract a BasisTransformer from it, without having to manually dig out the AO-2-MO transformation coefficients from the depths of the driver object:

[5]:
from qiskit_nature.second_q.formats.qcschema_translator import get_ao_to_mo_from_qcschema

basis_transformer = get_ao_to_mo_from_qcschema(qcschema)
[6]:
mo_problem = basis_transformer.transform(ao_problem)
print(mo_problem.basis)
ElectronicBasis.MO
[7]:
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:30 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.