Skip to content

Commit

Permalink
Update tutorials (#108)
Browse files Browse the repository at this point in the history
* Updated tutorials to qiskit nature code basi

* Add tutorial index and aux file

* fix tutorial imports

* fix tutorial note link

* Update docs/tutorials/01_electronic_structure.ipynb

Co-authored-by: Max Rossmannek <[email protected]>

* Update docs/tutorials/01_electronic_structure.ipynb

Co-authored-by: Max Rossmannek <[email protected]>

* Update docs/tutorials/02_vibronic_structure.ipynb

Co-authored-by: Max Rossmannek <[email protected]>

* tutorials updated after review

* fix renaming

* Remove pyscf deprecation msgs

* updates from review

* one more fix

Co-authored-by: Manoel Marques <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
  • Loading branch information
4 people authored Apr 1, 2021
1 parent 37571a5 commit d4ebb7c
Show file tree
Hide file tree
Showing 31 changed files with 2,015 additions and 2,285 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test/**/*.npz

# Django stuff:
*.log
!docs/tutorials/aux_files/*.log
.static_storage/
.media/
local_settings.py
Expand Down
19 changes: 1 addition & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,13 @@
templates_path = ['theme/']
html_css_files = ['style.css', 'custom.css']

nbsphinx_timeout = 180
nbsphinx_timeout = 360
nbsphinx_execute = os.getenv('QISKIT_DOCS_BUILD_TUTORIALS', 'never')
nbsphinx_widgets_path = ''
exclude_patterns = ['_build', '**.ipynb_checkpoints']
nbsphinx_thumbnails = {
}

nbsphinx_prolog = """
{% set docname = env.doc2path(env.docname, base=None) %}
.. only:: html
.. role:: raw-html(raw)
:format: html
.. note::
This page was generated from `{{ docname }}`__.
Run interactively in the `IBM Quantum lab <https://quantum-computing.ibm.com/jupyter/tutorial/{{ env.doc2path(env.docname, base=None)|replace("tutorials/", "") }}>`_.
__ https://github.com/Qiskit/qiskit-optimization/blob/master/docs/{{ docname }}
"""

# -----------------------------------------------------------------------------
# Autosummary
# -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Qiskit Nature documentation

API References <apidocs/qiskit_nature>
Release Notes <release_notes>
Tutorials <tutorials/index>

.. Hiding - Indices and tables
:ref:`genindex`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/bpa/opt/anaconda3/envs/qiskit-nature/lib/python3.7/site-packages/pyscf/lib/misc.py:46: H5pyDeprecationWarning: Using default_file_mode other than 'r' is deprecated. Pass the mode to h5py.File() instead.\n",
" h5py.get_config().default_file_mode = 'a'\n"
]
}
],
"source": [
"from qiskit.chemistry.drivers import PySCFDriver, UnitsType, Molecule\n",
"from qiskit_nature.drivers import PySCFDriver, UnitsType, Molecule\n",
"molecule = Molecule(geometry=[['H', [0., 0., 0.]],\n",
" ['H', [0., 0., 0.735]]],\n",
" charge=0, multiplicity=1)\n",
Expand Down Expand Up @@ -119,192 +128,138 @@
"* The Jordan-Wigner 'jordan_wigner' mapping (über das paulische äquivalenzverbot. In The Collected Works of Eugene Paul Wigner (pp. 109-129). Springer, Berlin, Heidelberg (1993)).\n",
"* The Parity 'parity' (The Journal of chemical physics, 137(22), 224109 (2012))\n",
"* The Bravyi-Kitaev 'bravyi_kitaev' (Annals of Physics, 298(1), 210-226 (2002))\n",
"* The Bravyi-Kitaev Super Fast 'bksf' (Annals of Physics, 298(1), 210-226 (2002))\n",
"\n",
"The Jordan-Wigner mapping is particularly interesting as it maps each Spin Orbital to a qubit (as shown on the Figure above). \n",
"\n",
"Here we set up an object which contains all the information about any transformation of the fermionic Hamiltonian to the qubits Hamiltonian. In this example we simply ask for the Jordan-Wigner mapping. "
"Here we set up the Electronic Structure Problem to generate the Second quantized operator and a qubit converter that will map it to a qubit operator."
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from qiskit.chemistry.transformations import (FermionicTransformation, \n",
" FermionicTransformationType, \n",
" FermionicQubitMappingType)\n",
"\n",
"fermionic_transformation = FermionicTransformation(\n",
" transformation=FermionicTransformationType.FULL,\n",
" qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER,\n",
" two_qubit_reduction=False,\n",
" freeze_core=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we now transform this Hamiltonian for the given driver defined above we get our qubit operator:"
"from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem\n",
"from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter\n",
"from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SummedOp([\n",
" -0.8105479805373266 * IIII,\n",
" 0.17218393261915552 * IIIZ,\n",
" -0.22575349222402472 * IIZI,\n",
" 0.1721839326191556 * IZII,\n",
" -0.22575349222402466 * ZIII,\n",
" 0.1209126326177663 * IIZZ,\n",
" 0.16892753870087912 * IZIZ,\n",
" 0.045232799946057854 * XXYY,\n",
" 0.045232799946057854 * YYYY,\n",
" 0.045232799946057854 * XXXX,\n",
" 0.045232799946057854 * YYXX,\n",
" 0.16614543256382414 * ZIIZ,\n",
" 0.16614543256382414 * IZZI,\n",
" 0.17464343068300453 * ZIZI,\n",
" 0.1209126326177663 * ZZII\n",
"])\n",
"{'num_particles': [1, 1], 'num_orbitals': 4, 'two_qubit_reduction': False, 'z2_symmetries': <qiskit.aqua.operators.legacy.weighted_pauli_operator.Z2Symmetries object at 0x123f6d940>}\n"
" +-+- * (0.18093119978423136+0j)\n",
"+ +--+ * (-0.18093119978423142+0j)\n",
"+ -++- * (-0.18093119978423142+0j)\n",
"+ -+-+ * (0.18093119978423144+0j)\n",
"+ IIIN * (-0.4718960072811406+0j)\n",
"+ IINI * (-1.2563390730032502+0j)\n",
"+ IINN * (0.4836505304710652+0j)\n",
"+ INII * (-0.4718960072811406+0j)\n",
"+ ININ * (0.6985737227320181+0j)\n",
"+ INNI * (0.6645817302552965+0j)\n",
"+ NIII * (-1.2563390730032502+0j)\n",
"+ NIIN * (0.6645817302552965+0j)\n",
"+ NINI * (0.6757101548035165+0j)\n",
"+ NNII * (0.4836505304710652+0j)\n"
]
}
],
"source": [
"qubit_op, _ = fermionic_transformation.transform(driver)\n",
"print(qubit_op)\n",
"print(fermionic_transformation.molecule_info)"
"es_problem = ElectronicStructureProblem(driver)\n",
"second_q_op = es_problem.second_q_ops()\n",
"print(second_q_op[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the minimal (STO-3G) basis set 4 qubits are required. We could even lower the qubit count by using the Parity mapping which allows to get rid of to qubits by symmetry considerations. "
"If we now transform this Hamiltonian for the given driver defined above we get our qubit operator:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SummedOp([\n",
" -1.052373245772859 * II,\n",
" 0.39793742484318007 * IZ,\n",
" -0.39793742484318007 * ZI,\n",
" -0.01128010425623538 * ZZ,\n",
" 0.18093119978423136 * XX\n",
"])\n"
"-0.8105479805373264 * IIII\n",
"- 0.22575349222402463 * ZIII\n",
"+ 0.17218393261915566 * IZII\n",
"+ 0.1209126326177663 * ZZII\n",
"- 0.22575349222402466 * IIZI\n",
"+ 0.17464343068300453 * ZIZI\n",
"+ 0.16614543256382414 * IZZI\n",
"+ 0.17218393261915566 * IIIZ\n",
"+ 0.16614543256382414 * ZIIZ\n",
"+ 0.16892753870087912 * IZIZ\n",
"+ 0.1209126326177663 * IIZZ\n",
"+ 0.045232799946057854 * XXXX\n",
"+ 0.045232799946057854 * YYXX\n",
"+ 0.045232799946057854 * XXYY\n",
"+ 0.045232799946057854 * YYYY\n"
]
}
],
"source": [
"fermionic_transformation_2 = FermionicTransformation(\n",
" transformation=FermionicTransformationType.FULL,\n",
" qubit_mapping=FermionicQubitMappingType.PARITY,\n",
" two_qubit_reduction=True,\n",
" freeze_core=False)\n",
"qubit_op_2, _ = fermionic_transformation_2.transform(driver)\n",
"print(qubit_op_2)"
"qubit_converter = QubitConverter(mapper=JordanWignerMapper())\n",
"qubit_op = qubit_converter.convert(second_q_op[0])\n",
"print(qubit_op)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This time only 2 qubits are needed. \n",
"\n",
"Another possibility is to use the Particle-Hole tranformation (Physical Review A, 98(2), 022322 (2018)). This shifts the vacuum state to a state lying in the N-particle Fock space. In this representation the HF (reference) state has a null energy and the optimization procedure is more faster. "
"In the minimal (STO-3G) basis set 4 qubits are required. We could even lower the qubit count by using the Parity mapping which allows to get rid of to qubits by symmetry considerations. "
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SummedOp([\n",
" 1.0264200106656571 * IIII,\n",
" 0.17218393261915554 * IIIZ,\n",
" -0.22575349222402463 * IIZI,\n",
" 0.17218393261915554 * IZII,\n",
" -0.22575349222402458 * ZIII,\n",
" 0.16892753870087912 * IZIZ,\n",
" 0.045232799946057854 * YYYY,\n",
" 0.045232799946057854 * XXYY,\n",
" 0.045232799946057854 * YYXX,\n",
" 0.045232799946057854 * XXXX,\n",
" 0.1209126326177663 * IIZZ,\n",
" 0.16614543256382414 * IZZI,\n",
" 0.16614543256382414 * ZIIZ,\n",
" 0.17464343068300453 * ZIZI,\n",
" 0.1209126326177663 * ZZII\n",
"])\n"
"(-1.0523732457728585+5.551115123125783e-17j) * II\n",
"+ (-0.3979374248431802+1.3877787807814457e-17j) * ZI\n",
"+ 0.3979374248431802 * IZ\n",
"- 0.01128010425623538 * ZZ\n",
"+ (0.18093119978423142+3.469446951953614e-18j) * XX\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/bpa/qiskit/qiskit-terra/qiskit/opflow/primitive_ops/pauli_sum_op.py:213: DeprecationWarning: Using the `__mul__` operator `A * B` as shorthand for `A.dot(B)` is deprecated as of version 0.17.0 and will be removed no earlier than 3 months after the release date. As an alternative, use the compose operator `B & A` in place of `A * B` as a replacement.\n",
" new_self.primitive * other.primitive,\n"
]
}
],
"source": [
"fermionic_transformation_3 = FermionicTransformation(\n",
" transformation=FermionicTransformationType.PARTICLE_HOLE,\n",
" qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER,\n",
" two_qubit_reduction=False,\n",
" freeze_core=False)\n",
"qubit_op_3, _ = fermionic_transformation_3.transform(driver)\n",
"print(qubit_op_3)"
"qubit_converter = QubitConverter(mapper = ParityMapper(), two_qubit_reduction=True)\n",
"qubit_op = qubit_converter.convert(second_q_op[0], num_particles=es_problem.num_particles)\n",
"print(qubit_op)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The list of available mappings and transformations are"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"*Transformations\n",
"FermionicTransformationType.FULL\n",
"FermionicTransformationType.PARTICLE_HOLE\n",
"\n",
"*Mappings\n",
"FermionicQubitMappingType.JORDAN_WIGNER\n",
"FermionicQubitMappingType.PARITY\n",
"FermionicQubitMappingType.BRAVYI_KITAEV\n"
]
}
],
"source": [
"print('*Transformations')\n",
"for fer_transform in FermionicTransformationType:\n",
" print(fer_transform)\n",
"\n",
"print('\\n*Mappings')\n",
"for fer_mapping in FermionicQubitMappingType:\n",
" print(fer_mapping)"
"This time only 2 qubits are needed. "
]
},
{
Expand All @@ -316,14 +271,14 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>0.23.0</td></tr><tr><td>Terra</td><td>0.16.0</td></tr><tr><td>Aer</td><td>0.7.0</td></tr><tr><td>Ignis</td><td>0.5.0</td></tr><tr><td>Aqua</td><td>0.8.0</td></tr><tr><td>IBM Q Provider</td><td>0.11.0</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17) \n",
"[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>2</td></tr><tr><td>Memory (Gb)</td><td>16.0</td></tr><tr><td colspan='2'>Tue Oct 20 18:02:17 2020 CEST</td></tr></table>"
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>0.24.1</td></tr><tr><td>Terra</td><td>0.17.0.dev0+ad88761</td></tr><tr><td>Aer</td><td>0.7.6</td></tr><tr><td>Ignis</td><td>0.5.2</td></tr><tr><td>Aqua</td><td>None</td></tr><tr><td>IBM Q Provider</td><td>0.12.2</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.7.10 (default, Feb 26 2021, 10:16:00) \n",
"[Clang 10.0.0 ]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>4</td></tr><tr><td>Memory (Gb)</td><td>16.0</td></tr><tr><td colspan='2'>Thu Apr 01 10:23:12 2021 CEST</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand All @@ -335,7 +290,7 @@
{
"data": {
"text/html": [
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2020.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2021.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand All @@ -350,13 +305,6 @@
"%qiskit_version_table\n",
"%qiskit_copyright"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -375,7 +323,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
"version": "3.7.10"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit d4ebb7c

Please sign in to comment.