Skip to content

Commit

Permalink
Fix documentation and init files (#116) (#138)
Browse files Browse the repository at this point in the history
* Fix documentation

* Refactor QubitConvertor to new location to avoid cyclic imports

Generally clean up imports and make them consistent

* Update navigation and text

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

* Update qiskit_nature/converters/second_quantization/__init__.py

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

* Update qiskit_nature/transformers/__init__.py

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

* Fix suggestion breakages

Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
(cherry picked from commit 445669e)

Co-authored-by: Steve Wood <[email protected]>
  • Loading branch information
mergify[bot] and woodsp-ibm authored Apr 14, 2021
1 parent f5a59c7 commit b99cf55
Show file tree
Hide file tree
Showing 107 changed files with 850 additions and 592 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ num_spin_orbitals = 2 * problem.molecule_data.num_molecular_orbitals

# setup the classical optimizer for VQE
from qiskit.algorithms.optimizers import L_BFGS_B

optimizer = L_BFGS_B()

# setup the mapper and qubit converter
from qiskit_nature.mappers.second_quantization import ParityMapper
from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter
from qiskit_nature.converters.second_quantization import QubitConverter

mapper = ParityMapper()
converter = QubitConverter(mapper=mapper, two_qubit_reduction=True)

Expand All @@ -101,21 +103,25 @@ qubit_op = converter.convert(main_op, num_particles=num_particles)

# setup the initial state for the ansatz
from qiskit_nature.circuit.library import HartreeFock

init_state = HartreeFock(num_spin_orbitals, num_particles, converter)

# setup the ansatz for VQE
from qiskit.circuit.library import TwoLocal

ansatz = TwoLocal(num_spin_orbitals, ['ry', 'rz'], 'cz')

# add the initial state
ansatz.compose(init_state, front=True)

# set the backend for the quantum computation
from qiskit import Aer

backend = Aer.get_backend('statevector_simulator')

# setup and run VQE
from qiskit.algorithms import VQE

algorithm = VQE(ansatz,
optimizer=optimizer,
quantum_instance=backend)
Expand Down
6 changes: 6 additions & 0 deletions docs/apidocs/qiskit_nature.converters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _qiskit_nature-converters:

.. automodule:: qiskit_nature.converters
:no-members:
:no-inherited-members:
:no-special-members:
6 changes: 6 additions & 0 deletions docs/apidocs/qiskit_nature.converters.second_quantization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _qiskit_nature-converters-second_quantization:

.. automodule:: qiskit_nature.converters.second_quantization
:no-members:
:no-inherited-members:
:no-special-members:
6 changes: 6 additions & 0 deletions docs/apidocs/qiskit_nature.mappers.second_quantization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _qiskit_nature-mappers-second_quantization:

.. automodule:: qiskit_nature.mappers.second_quantization
:no-members:
:no-inherited-members:
:no-special-members:
7 changes: 7 additions & 0 deletions docs/apidocs/qiskit_nature.operators.second_quantization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _qiskit_nature-operators-second_quantization:

.. automodule:: qiskit_nature.operators.second_quantization
:no-members:
:no-inherited-members:
:no-special-members:

7 changes: 7 additions & 0 deletions docs/apidocs/qiskit_nature.problems.second_quantization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _qiskit_nature-problems-second_quantization:

.. automodule:: qiskit_nature.problems.second_quantization
:no-members:
:no-inherited-members:
:no-special-members:

4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
###########################
Qiskit Nature documentation
Qiskit Nature Documentation
###########################

.. toctree::
:maxdepth: 2

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

Expand Down
107 changes: 45 additions & 62 deletions docs/tutorials/01_electronic_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"from qiskit_nature.drivers import PySCFDriver, UnitsType, Molecule\n",
"molecule = Molecule(geometry=[['H', [0., 0., 0.]],\n",
Expand All @@ -111,7 +102,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For further information about the drivers see https://qiskit.org/documentation/apidoc/qiskit.chemistry.drivers.html"
"For further information about the drivers see https://qiskit.org/documentation/nature/apidocs/qiskit_nature.drivers.html"
]
},
{
Expand All @@ -136,38 +127,38 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem\n",
"from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter\n",
"from qiskit_nature.problems.second_quantization import ElectronicStructureProblem\n",
"from qiskit_nature.converters.second_quantization import QubitConverter\n",
"from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" +-+- * (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"
" +-+- * (0.18093119978423158+0j)\n",
"+ +--+ * (-0.18093119978423156+0j)\n",
"+ -++- * (-0.18093119978423156+0j)\n",
"+ -+-+ * (0.18093119978423156+0j)\n",
"+ IIIN * (-0.4718960072811405+0j)\n",
"+ IINI * (-1.2563390730032507+0j)\n",
"+ IINN * (0.48365053047106565+0j)\n",
"+ INII * (-0.4718960072811405+0j)\n",
"+ ININ * (0.6985737227320187+0j)\n",
"+ INNI * (0.6645817302552972+0j)\n",
"+ NIII * (-1.2563390730032507+0j)\n",
"+ NIIN * (0.6645817302552972+0j)\n",
"+ NINI * (0.675710154803517+0j)\n",
"+ NNII * (0.48365053047106565+0j)\n"
]
}
],
Expand All @@ -186,28 +177,28 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-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"
"-0.8105479805373266 * IIII\n",
"- 0.22575349222402513 * ZIII\n",
"+ 0.17218393261915543 * IZII\n",
"+ 0.12091263261776641 * ZZII\n",
"- 0.22575349222402516 * IIZI\n",
"+ 0.17464343068300467 * ZIZI\n",
"+ 0.1661454325638243 * IZZI\n",
"+ 0.17218393261915546 * IIIZ\n",
"+ 0.1661454325638243 * ZIIZ\n",
"+ 0.16892753870087926 * IZIZ\n",
"+ 0.12091263261776641 * IIZZ\n",
"+ 0.04523279994605789 * XXXX\n",
"+ 0.04523279994605789 * YYXX\n",
"+ 0.04523279994605789 * XXYY\n",
"+ 0.04523279994605789 * YYYY\n"
]
}
],
Expand All @@ -221,31 +212,23 @@
"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. "
"In the minimal (STO-3G) basis set 4 qubits are required. We can reduce the number of qubits by using the Parity mapping, which allows for the removal of 2 qubits by exploiting known symmetries arising from the mapping. "
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(-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"
"(-1.052373245772859-2.7755575615628914e-17j) * II\n",
"+ (-0.3979374248431805+1.3877787807814457e-17j) * ZI\n",
"+ (0.3979374248431805-2.7755575615628914e-17j) * IZ\n",
"- 0.011280104256235296 * ZZ\n",
"+ (0.18093119978423153+3.469446951953614e-18j) * XX\n"
]
}
],
Expand Down Expand Up @@ -323,7 +306,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.6.1"
}
},
"nbformat": 4,
Expand Down
21 changes: 6 additions & 15 deletions docs/tutorials/02_vibrational_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"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"
]
}
],
"outputs": [],
"source": [
"from qiskit_nature.drivers import GaussianForcesDriver\n",
"# if you ran Gaussian elsewhere and already have the output file\n",
Expand Down Expand Up @@ -200,12 +191,12 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from qiskit_nature.problems.second_quantization.vibrational.vibrational_structure_problem import VibrationalStructureProblem\n",
"from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter\n",
"from qiskit_nature.problems.second_quantization import VibrationalStructureProblem\n",
"from qiskit_nature.converters.second_quantization import QubitConverter\n",
"from qiskit_nature.mappers.second_quantization import DirectMapper\n",
"\n",
"vibrational_problem = VibrationalStructureProblem(driver, num_modals=2, truncation_order=2)\n",
Expand Down Expand Up @@ -753,7 +744,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.6.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit b99cf55

Please sign in to comment.