diff --git a/README.md b/README.md index c54d5babc6..0cc6a6d4f1 100644 --- a/README.md +++ b/README.md @@ -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) @@ -101,10 +103,12 @@ 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 @@ -112,10 +116,12 @@ 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) diff --git a/docs/apidocs/qiskit_nature.converters.rst b/docs/apidocs/qiskit_nature.converters.rst new file mode 100644 index 0000000000..a8c2074173 --- /dev/null +++ b/docs/apidocs/qiskit_nature.converters.rst @@ -0,0 +1,6 @@ +.. _qiskit_nature-converters: + +.. automodule:: qiskit_nature.converters + :no-members: + :no-inherited-members: + :no-special-members: diff --git a/docs/apidocs/qiskit_nature.converters.second_quantization.rst b/docs/apidocs/qiskit_nature.converters.second_quantization.rst new file mode 100644 index 0000000000..81d4706470 --- /dev/null +++ b/docs/apidocs/qiskit_nature.converters.second_quantization.rst @@ -0,0 +1,6 @@ +.. _qiskit_nature-converters-second_quantization: + +.. automodule:: qiskit_nature.converters.second_quantization + :no-members: + :no-inherited-members: + :no-special-members: diff --git a/docs/apidocs/qiskit_nature.mappers.second_quantization.rst b/docs/apidocs/qiskit_nature.mappers.second_quantization.rst new file mode 100644 index 0000000000..aa32d6c997 --- /dev/null +++ b/docs/apidocs/qiskit_nature.mappers.second_quantization.rst @@ -0,0 +1,6 @@ +.. _qiskit_nature-mappers-second_quantization: + +.. automodule:: qiskit_nature.mappers.second_quantization + :no-members: + :no-inherited-members: + :no-special-members: diff --git a/docs/apidocs/qiskit_nature.operators.second_quantization.rst b/docs/apidocs/qiskit_nature.operators.second_quantization.rst new file mode 100644 index 0000000000..5918335923 --- /dev/null +++ b/docs/apidocs/qiskit_nature.operators.second_quantization.rst @@ -0,0 +1,7 @@ +.. _qiskit_nature-operators-second_quantization: + +.. automodule:: qiskit_nature.operators.second_quantization + :no-members: + :no-inherited-members: + :no-special-members: + \ No newline at end of file diff --git a/docs/apidocs/qiskit_nature.problems.second_quantization.rst b/docs/apidocs/qiskit_nature.problems.second_quantization.rst new file mode 100644 index 0000000000..66152b2a0a --- /dev/null +++ b/docs/apidocs/qiskit_nature.problems.second_quantization.rst @@ -0,0 +1,7 @@ +.. _qiskit_nature-problems-second_quantization: + +.. automodule:: qiskit_nature.problems.second_quantization + :no-members: + :no-inherited-members: + :no-special-members: + \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index fda5e1864c..68e08c7c97 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,11 +1,11 @@ ########################### -Qiskit Nature documentation +Qiskit Nature Documentation ########################### .. toctree:: :maxdepth: 2 - API References + API Reference Tutorials Release Notes diff --git a/docs/tutorials/01_electronic_structure.ipynb b/docs/tutorials/01_electronic_structure.ipynb index 23dcbfac20..c3cc4785f2 100644 --- a/docs/tutorials/01_electronic_structure.ipynb +++ b/docs/tutorials/01_electronic_structure.ipynb @@ -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", @@ -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" ] }, { @@ -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" ] } ], @@ -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" ] } ], @@ -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" ] } ], @@ -323,7 +306,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/docs/tutorials/02_vibrational_structure.ipynb b/docs/tutorials/02_vibrational_structure.ipynb index 749ebe121b..6b3d9df751 100644 --- a/docs/tutorials/02_vibrational_structure.ipynb +++ b/docs/tutorials/02_vibrational_structure.ipynb @@ -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", @@ -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", @@ -753,7 +744,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/docs/tutorials/03_ground_state_solvers.ipynb b/docs/tutorials/03_ground_state_solvers.ipynb index 4946a9b88d..9524e4249f 100644 --- a/docs/tutorials/03_ground_state_solvers.ipynb +++ b/docs/tutorials/03_ground_state_solvers.ipynb @@ -22,14 +22,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from qiskit import Aer\n", "from qiskit_nature.drivers import PySCFDriver, UnitsType, Molecule\n", - "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\n", "\n", "molecule = Molecule(geometry=[['H', [0., 0., 0.]],\n", @@ -76,14 +76,14 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from qiskit.providers.aer import StatevectorSimulator\n", "from qiskit import Aer\n", "from qiskit.utils import QuantumInstance\n", - "from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import VQEUCCFactory\n", + "from qiskit_nature.algorithms import VQEUCCFactory\n", "\n", "quantum_instance = QuantumInstance(backend = Aer.get_backend('statevector_simulator'))\n", "vqe_solver = VQEUCCFactory(quantum_instance)" @@ -104,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -147,23 +147,23 @@ " \n", "=== MEASURED OBSERVABLES ===\n", " \n", - " 0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000\n", + " 0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: -0.000\n", " \n", "=== DIPOLE MOMENTS ===\n", " \n", "~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487]\n", " \n", " 0: \n", - " * Electronic dipole moment (a.u.): [0.0 0.0 1.38894891]\n", - " - computed part: [0.0 0.0 1.38894891]\n", - " > Dipole moment (a.u.): [0.0 0.0 -0.00000021] Total: 0.00000021\n", - " (debye): [0.0 0.0 -0.00000053] Total: 0.00000053\n", + " * Electronic dipole moment (a.u.): [0.0 0.0 1.38894866]\n", + " - computed part: [0.0 0.0 1.38894866]\n", + " > Dipole moment (a.u.): [0.0 0.0 0.00000004] Total: 0.00000004\n", + " (debye): [0.0 0.0 0.0000001] Total: 0.0000001\n", " \n" ] } ], "source": [ - "from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver\n", + "from qiskit_nature.algorithms import GroundStateEigensolver\n", "\n", "calc = GroundStateEigensolver(qubit_converter, vqe_solver)\n", "res = calc.solve(es_problem)\n", @@ -233,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -242,7 +242,7 @@ "text": [ "=== GROUND STATE ENERGY ===\n", " \n", - "* Vibrational ground state energy (cm^-1): (1e-11+0j)\n", + "* Vibrational ground state energy (cm^-1): (1.1e-11-0j)\n", "The number of occupied modals is\n", "- Mode 0: [0.0, 0.0, 0.0, 0.0]\n", "\n", @@ -250,7 +250,7 @@ "\n", "=== GROUND STATE ENERGY ===\n", " \n", - "* Vibrational ground state energy (cm^-1): (2553.464851175482+0j)\n", + "* Vibrational ground state energy (cm^-1): (2553.464851175474+0j)\n", "The number of occupied modals is\n", "- Mode 0: [0.9999999999999999, 0.9999999999999999, 0.9999999999999999, 0.9999999999999999]\n" ] @@ -258,8 +258,8 @@ ], "source": [ "from qiskit_nature.drivers import GaussianForcesDriver\n", - "from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import NumPyMinimumEigensolverFactory\n", - "from qiskit_nature.problems.second_quantization.vibrational.vibrational_structure_problem import VibrationalStructureProblem\n", + "from qiskit_nature.algorithms import NumPyMinimumEigensolverFactory\n", + "from qiskit_nature.problems.second_quantization import VibrationalStructureProblem\n", "from qiskit_nature.mappers.second_quantization import DirectMapper\n", "\n", "driver = GaussianForcesDriver(logfile='aux_files/CO2_freq_B3LYP_ccpVDZ.log')\n", @@ -336,7 +336,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/docs/tutorials/04_excited_states_solvers.ipynb b/docs/tutorials/04_excited_states_solvers.ipynb index 39844012a8..af0c9e0883 100644 --- a/docs/tutorials/04_excited_states_solvers.ipynb +++ b/docs/tutorials/04_excited_states_solvers.ipynb @@ -22,22 +22,13 @@ }, { "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", - "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\n", "\n", "molecule = Molecule(geometry=[['H', [0., 0., 0.]],\n", @@ -63,11 +54,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "from qiskit_nature.algorithms.excited_states_solvers.eigensolver_factories import NumPyEigensolverFactory\n", + "from qiskit_nature.algorithms import NumPyEigensolverFactory\n", "\n", "numpy_solver = NumPyEigensolverFactory(use_default_filter_criterion=True)" ] @@ -119,15 +110,13 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from qiskit import Aer\n", "from qiskit.utils import QuantumInstance\n", - "from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver\n", - "from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import VQEUCCFactory\n", - "from qiskit_nature.algorithms.excited_states_solvers import QEOM\n", + "from qiskit_nature.algorithms import GroundStateEigensolver, QEOM, VQEUCCFactory\n", "\n", "# This first part sets the ground state solver\n", "# see more about this part in the ground state calculation tutorial\n", @@ -150,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -214,34 +203,34 @@ "=== EXCITED STATE ENERGIES ===\n", " \n", " 1: \n", - "* Electronic excited state energy (Hartree): -1.244586755338\n", - "> Total excited state energy (Hartree): -0.524617760889\n", + "* Electronic excited state energy (Hartree): -1.244586754624\n", + "> Total excited state energy (Hartree): -0.524617760175\n", " 2: \n", - "* Electronic excited state energy (Hartree): -0.882724355739\n", - "> Total excited state energy (Hartree): -0.16275536129\n", + "* Electronic excited state energy (Hartree): -0.882724355025\n", + "> Total excited state energy (Hartree): -0.162755360576\n", " 3: \n", - "* Electronic excited state energy (Hartree): -0.224913458334\n", - "> Total excited state energy (Hartree): 0.495055536115\n", + "* Electronic excited state energy (Hartree): -0.22491345762\n", + "> Total excited state energy (Hartree): 0.495055536829\n", " \n", "=== MEASURED OBSERVABLES ===\n", " \n", - " 0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000\n", + " 0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: -0.000\n", " \n", "=== DIPOLE MOMENTS ===\n", " \n", "~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487]\n", " \n", " 0: \n", - " * Electronic dipole moment (a.u.): [0.0 0.0 1.38894891]\n", - " - computed part: [0.0 0.0 1.38894891]\n", - " > Dipole moment (a.u.): [0.0 0.0 -0.00000021] Total: 0.00000021\n", - " (debye): [0.0 0.0 -0.00000053] Total: 0.00000053\n", + " * Electronic dipole moment (a.u.): [0.0 0.0 1.38894866]\n", + " - computed part: [0.0 0.0 1.38894866]\n", + " > Dipole moment (a.u.): [0.0 0.0 0.00000004] Total: 0.00000004\n", + " (debye): [0.0 0.0 0.0000001] Total: 0.0000001\n", " \n" ] } ], "source": [ - "from qiskit_nature.algorithms.excited_states_solvers import ExcitedStatesEigensolver\n", + "from qiskit_nature.algorithms import ExcitedStatesEigensolver\n", "\n", "numpy_excited_states_calculation = ExcitedStatesEigensolver(qubit_converter, numpy_solver)\n", "numpy_results = numpy_excited_states_calculation.solve(es_problem)\n", @@ -414,7 +403,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/docs/tutorials/05_Sampling_potential_energy_surfaces.ipynb b/docs/tutorials/05_Sampling_potential_energy_surfaces.ipynb index 6c5ac24303..21c1507c5c 100644 --- a/docs/tutorials/05_Sampling_potential_energy_surfaces.ipynb +++ b/docs/tutorials/05_Sampling_potential_energy_surfaces.ipynb @@ -18,18 +18,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": [ "# import common packages\n", "import numpy as np\n", @@ -49,9 +40,9 @@ "\n", "# qiskit nature imports\n", "from qiskit_nature.problems.second_quantization import ElectronicStructureProblem\n", - "from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter\n", + "from qiskit_nature.converters.second_quantization import QubitConverter\n", "from qiskit_nature.mappers.second_quantization import JordanWignerMapper\n", - "from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver\n", + "from qiskit_nature.algorithms import GroundStateEigensolver\n", "from qiskit_nature.drivers import PySCFDriver, UnitsType, Molecule\n", "from qiskit_nature.algorithms.pes_samplers import BOPESSampler, Extrapolator\n", "\n", @@ -535,7 +526,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/docs/tutorials/06_calculating_thermodynamic_observables.ipynb b/docs/tutorials/06_calculating_thermodynamic_observables.ipynb index f6b347c7cc..76cfe6eb82 100644 --- a/docs/tutorials/06_calculating_thermodynamic_observables.ipynb +++ b/docs/tutorials/06_calculating_thermodynamic_observables.ipynb @@ -9,18 +9,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "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": [ "# imports\n", "import numpy as np\n", @@ -33,13 +24,12 @@ "from qiskit.algorithms import NumPyMinimumEigensolver, VQE\n", "\n", "from qiskit_nature.drivers import PySCFDriver, UnitsType, Molecule\n", - "from qiskit_nature.problems.second_quantization.electronic.electronic_structure_problem 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\n", - "from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver\n", - "from qiskit_nature.algorithms.pes_samplers import BOPESSampler\n", + "from qiskit_nature.algorithms import GroundStateEigensolver \n", "import qiskit_nature.constants as const\n", - "from qiskit_nature.algorithms.pes_samplers.potentials.energy_surface_spline import EnergySurface1DSpline\n", + "from qiskit_nature.algorithms.pes_samplers import BOPESSampler, EnergySurface1DSpline\n", "from thermodynamics_utils.thermodynamics import constant_volume_heat_capacity\n", "from thermodynamics_utils.vibrational_structure_fd import VibrationalStructure1DFD\n", "from thermodynamics_utils.partition_function import DiatomicPartitionFunction\n", @@ -508,7 +498,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/qiskit_nature/__init__.py b/qiskit_nature/__init__.py index 05693daa5a..561939fe66 100644 --- a/qiskit_nature/__init__.py +++ b/qiskit_nature/__init__.py @@ -16,111 +16,11 @@ .. currentmodule:: qiskit_nature -This is Qiskit Nature module that provides for experimentation with -domain problems such as ground state energy and excited state energies of molecules. +The Qiskit Nature module provides function to experiment with quantum computing for natural +science problems, such as in chemistry and physics. For example computing the ground state energy +or excited state energies of molecules. -Overview -======== - -This is an overview of the workings of the nature sciences module and how it may be used. There -are different levels of exposure to its functionality, allowing for experimentation at different -abstractions. The outline below starts with the flow that provides the most control of the -process. - -A classical chemistry driver is first instantiated, from the available :mod:`~.drivers`, -by means of a molecule specification, along with other configuration such as basis set and method -(RHF, ROHF, UHF). This configuration may include custom settings for the specific driver for more -custom control over the driver's behavior. When the driver is run the output is a mostly driver -independent :class:`qiskit_nature.drivers.QMolecule`. This contains various quantities that were -computed including one and two-body electron integrals that are used as input -:class:`~qiskit_nature.FermionicOperator`. Mostly driver independent means that these integrals, -for example, will be there from every driver but the values may differ due to how each underlying -chemistry library/program computes them. Also some fields in the QMolecule may not be populated by -all drivers, for instance dipole integrals are not output from the PyQuante driver, and hence the -dipole moment cannot be computed by qiskit_nature when using this driver. The FermionicOperator -once created can then be converted/mapped to a qubit operator for use as input to an -algorithm. The operator must be in qubit form at this stage since the execution target of the -algorithm will be a quantum device, or simulator ,comprised of qubits and the mapping is needed as -qubits behave differently than fermions. Once the algorithm is run it will compute the electronic -part of the quantity, such as the electronic ground state energy. To get the total ground state -energy this can be combined with the nuclear repulsion energy in the QMolecule. - -Instead of using the FermionicOperator the :class:`.core.Hamiltonian` may be used. This -itself uses the FermionicOperator but provides a higher level of function to simplify use. For -instance the FermionicOperator supports particle-hole transformation and different mappings. And to -compute dipole moments each of the X, Y and Z dipole integrals must be prepared, as individual -FermionicOperators, in a like manner to the main electronic energy one, i.e. same transformations, -and eventually same qubit mapping. The core.Hamiltonian class does all this and more, such as -orbital reductions, frozen core and automatic symmetry reduction. When run with a QMolecule output -from a driver it produces qubit operators that can be given directly to algorithms for -the computation. Also available are several properties, such as number of particles and number of -orbitals, that are needed to correctly instantiate chemistry specific components such as -:class:`~.components.variational_forms.UCCSD` and :class:`~.components.initial_states.HartreeFock`. -Using the FermionicOperator directly requires taking the initial values for the QMolecule and then -keeping track of any changes based on any orbital elimination and/or freezing, and/or Z2Symmetry -reductions that are done. Once the output qubit operators have been used with an algorithm, -to compute the electronic result, this result can be fed back to the core.Hamiltonian, to -:meth:`~.core.Hamiltonian.process_algorithm_result` which will then compute a final total result -including a user friendly formatted text result that may be printed. - -Lastly the chemistry :mod:`~.applications` may be used. These are given a chemistry driver and, -in the case of :class:`~applications.MolecularGroundStateEnergy` an optional instance of a -:class:`~qiskit.algorithms.MinimumEigensolver`, such as :class:`~qiskit.algorithms.VQE`. -Optional since components such as :class:`~.components.variational_forms.UCCSD` need certain -information that may be unknown at this point. So alternatively, when its method -:meth:`~applications.MolecularGroundStateEnergy.compute_energy` is run a callback can be provided -which will later be passed information, such as number of particles and orbitals, and allow a -complete MinimumEigensolver to be built using say UCCSD with HartreeFock, and subsequently returned -to the application and run. MinimumEigensolver itself uses the core.Hamiltonian class wrapping -it to form this high level application. - -Mappings -++++++++ -To map the FermionicOperator to a qubit operator the chemistry module supports the following -mappings: - -Jordan Wigner - The `Jordan-Wigner transformation `__, - maps spin operators onto fermionic creation and annihilation operators. - It was proposed by Ernst Pascual Jordan and Eugene Paul Wigner - for one-dimensional lattice models, - but now two-dimensional analogues of the transformation have also been created. - The Jordan–Wigner transformation is often used to exactly solve 1D spin-chains - by transforming the spin operators to fermionic operators and then diagonalizing - in the fermionic basis. - -Parity - The `parity-mapping transformation `__. - optimizes encodings of fermionic many-body systems by qubits - in the presence of symmetries. - Such encodings eliminate redundant degrees of freedom in a way that preserves - a simple structure of the system Hamiltonian enabling quantum simulations with fewer qubits. - -Bravyi-Kitaev - Also known as *binary-tree-based qubit mapping*, the `Bravyi-Kitaev transformation - `__ - is a method of mapping the occupation state of a - fermionic system onto qubits. This transformation maps the Hamiltonian of :math:`n` - interacting fermions to an :math:`\mathcal{O}(\log n)` - local Hamiltonian of :math:`n` qubits. - This is an improvement in locality over the Jordan–Wigner transformation, which results - in an :math:`\mathcal{O}(n)` local qubit Hamiltonian. - The Bravyi–Kitaev transformation was proposed by Sergey B. Bravyi and Alexei Yu. Kitaev. - -Bravyi-Kitaev Superfast - `Bravyi-Kitaev Superfast (BKSF) `__ algorithm - is a mapping from fermionic operators to qubit operators. BKSF algorithm defines an abstract - model where the fermionic modes are mapped to vertices of an interaction graph. The edges of - the graph correspond to the interaction between the modes. The graph can be constructed from - the Hamiltonian. The simulation is done by putting qubits on the edges of the graph. Each - fermionic operator costs :math:`\mathcal{O}(d)` qubit operations, where :math:`d` is the - degree of the interaction graph. The BKSF was proposed by Kanav Setia and James D. Whitfield. - - -The classes and submodules of qiskit_nature are now listed for reference: - -Chemistry Error -=============== +The top-level classes and submodules of qiskit_nature are: .. autosummary:: :toctree: ../stubs/ @@ -136,6 +36,7 @@ algorithms circuit + converters drivers mappers operators diff --git a/qiskit_nature/algorithms/__init__.py b/qiskit_nature/algorithms/__init__.py index f8803e91d4..ed0c07579d 100644 --- a/qiskit_nature/algorithms/__init__.py +++ b/qiskit_nature/algorithms/__init__.py @@ -11,22 +11,17 @@ # that they have been altered from the originals. """ -Nature Sciences specific algorithms (:mod:`qiskit_nature.algorithms`) -===================================================================== -These are nature sciences specific algorithms. As they rely on nature -sciences specific knowledge and/or function that are here. +Algorithms (:mod:`qiskit_nature.algorithms`) +============================================ .. currentmodule:: qiskit_nature.algorithms -Nature Algorithms -================= -These are algorithms configured and/or functioning using chemistry specific knowledge. See also -:mod:`~qiskit.algorithms` for other algorithms in these categories which may also -be used for chemistry problems such as :class:`~qiskit.algorithms.VQE`. +These are natural science algorithms to solve specific problems such as finding the ground state +energy, excited state energies or potential energy surfaces. Excited State Solvers +++++++++++++++++++++ -Algorithms that can find the eigenvalues of an operator, i.e. excited states for chemistry. +Algorithms that can find the eigenvalues of an operator, e.g. excited states for chemistry. The interface for such solvers, @@ -57,7 +52,7 @@ Ground State Solvers ++++++++++++++++++++ -Algorithms that can find the minimum eigenvalue of an operator, i.e. ground state for chemistry. +Algorithms that can find the minimum eigenvalue of an operator, e.g. ground state for chemistry. The interface for such solvers, diff --git a/qiskit_nature/algorithms/excited_states_solvers/excited_states_eigensolver.py b/qiskit_nature/algorithms/excited_states_solvers/excited_states_eigensolver.py index 86c423cc7a..75c0ae0ec4 100644 --- a/qiskit_nature/algorithms/excited_states_solvers/excited_states_eigensolver.py +++ b/qiskit_nature/algorithms/excited_states_solvers/excited_states_eigensolver.py @@ -18,10 +18,10 @@ from qiskit.algorithms import Eigensolver from qiskit.opflow import PauliSumOp +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.eigenstate_result import EigenstateResult +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import EigenstateResult from .excited_states_solver import ExcitedStatesSolver from .eigensolver_factories import EigensolverFactory diff --git a/qiskit_nature/algorithms/excited_states_solvers/excited_states_solver.py b/qiskit_nature/algorithms/excited_states_solvers/excited_states_solver.py index 44e0ed2476..f05a0729bd 100644 --- a/qiskit_nature/algorithms/excited_states_solvers/excited_states_solver.py +++ b/qiskit_nature/algorithms/excited_states_solvers/excited_states_solver.py @@ -18,8 +18,8 @@ from qiskit.opflow import PauliSumOp from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.eigenstate_result import EigenstateResult +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import EigenstateResult class ExcitedStatesSolver(ABC): diff --git a/qiskit_nature/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/algorithms/excited_states_solvers/qeom.py index 330d8e6c8b..317b3427be 100644 --- a/qiskit_nature/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/algorithms/excited_states_solvers/qeom.py @@ -27,8 +27,8 @@ double_commutator, PauliSumOp, ) from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.eigenstate_result import EigenstateResult +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import EigenstateResult from .excited_states_solver import ExcitedStatesSolver from ..ground_state_solvers import GroundStateSolver diff --git a/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py b/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py index 7b5e87a103..56b0b0fc9b 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py +++ b/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py @@ -25,11 +25,11 @@ from qiskit.opflow import OperatorBase, PauliSumOp from qiskit.utils.validation import validate_min from qiskit_nature.exceptions import QiskitNatureError -from qiskit_nature.circuit.library.ansatzes import UCC +from qiskit_nature.circuit.library import UCC from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.electronic_structure_result import ElectronicStructureResult +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import ElectronicStructureResult from .minimum_eigensolver_factories import MinimumEigensolverFactory from .ground_state_eigensolver import GroundStateEigensolver diff --git a/qiskit_nature/algorithms/ground_state_solvers/ground_state_eigensolver.py b/qiskit_nature/algorithms/ground_state_solvers/ground_state_eigensolver.py index c940fc39a2..3e2ffb5bfb 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/ground_state_eigensolver.py +++ b/qiskit_nature/algorithms/ground_state_solvers/ground_state_eigensolver.py @@ -23,9 +23,9 @@ from qiskit.opflow import OperatorBase, PauliSumOp, StateFn, CircuitSampler from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.eigenstate_result import EigenstateResult +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import EigenstateResult from .ground_state_solver import GroundStateSolver from .minimum_eigensolver_factories import MinimumEigensolverFactory diff --git a/qiskit_nature/algorithms/ground_state_solvers/ground_state_solver.py b/qiskit_nature/algorithms/ground_state_solvers/ground_state_solver.py index f312e690ef..997292711d 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/ground_state_solver.py +++ b/qiskit_nature/algorithms/ground_state_solvers/ground_state_solver.py @@ -23,9 +23,9 @@ from qiskit.opflow import OperatorBase, PauliSumOp from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.results.eigenstate_result import EigenstateResult +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import BaseProblem +from qiskit_nature.results import EigenstateResult class GroundStateSolver(ABC): diff --git a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/minimum_eigensolver_factory.py b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/minimum_eigensolver_factory.py index f608bc562c..988920017a 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/minimum_eigensolver_factory.py +++ b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/minimum_eigensolver_factory.py @@ -16,7 +16,7 @@ from qiskit.algorithms import MinimumEigensolver -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.problems.second_quantization import BaseProblem diff --git a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/numpy_minimum_eigensolver_factory.py b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/numpy_minimum_eigensolver_factory.py index 6957ec77dc..15a8088808 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/numpy_minimum_eigensolver_factory.py +++ b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/numpy_minimum_eigensolver_factory.py @@ -17,8 +17,8 @@ import numpy as np from qiskit.algorithms import MinimumEigensolver, NumPyMinimumEigensolver -from ....operators.second_quantization.qubit_converter import QubitConverter -from ....problems.second_quantization.base_problem import BaseProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import BaseProblem from .minimum_eigensolver_factory import MinimumEigensolverFactory diff --git a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_ucc_factory.py b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_ucc_factory.py index 71ede832bf..c8fb412d42 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_ucc_factory.py +++ b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_ucc_factory.py @@ -22,12 +22,10 @@ from qiskit.opflow.gradients import GradientBase from qiskit.utils import QuantumInstance -from qiskit_nature.circuit.library.ansatzes import UCC, UCCSD -from qiskit_nature.circuit.library.initial_states import HartreeFock +from qiskit_nature.circuit.library import HartreeFock, UCC, UCCSD from qiskit_nature.drivers import QMolecule -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic.electronic_structure_problem import \ - ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem from .minimum_eigensolver_factory import MinimumEigensolverFactory diff --git a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_uvcc_factory.py b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_uvcc_factory.py index 597b692442..cbf341f407 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_uvcc_factory.py +++ b/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_uvcc_factory.py @@ -21,12 +21,10 @@ from qiskit.opflow import ExpectationBase from qiskit.opflow.gradients import GradientBase from qiskit.utils import QuantumInstance -from qiskit_nature.circuit.library import VSCF -from qiskit_nature.circuit.library.ansatzes import UVCC, UVCCSD +from qiskit_nature.circuit.library import UVCC, UVCCSD, VSCF from qiskit_nature.drivers import WatsonHamiltonian -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.vibrational.vibrational_structure_problem import \ - VibrationalStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization.vibrational import VibrationalStructureProblem from .minimum_eigensolver_factory import MinimumEigensolverFactory diff --git a/qiskit_nature/algorithms/pes_samplers/__init__.py b/qiskit_nature/algorithms/pes_samplers/__init__.py index f76c3619a5..3fff20396c 100644 --- a/qiskit_nature/algorithms/pes_samplers/__init__.py +++ b/qiskit_nature/algorithms/pes_samplers/__init__.py @@ -54,11 +54,11 @@ VibrationalStructureBase """ -from .bopes_sampler import BOPESSampler from .extrapolator import (Extrapolator, DifferentialExtrapolator, PCAExtrapolator, PolynomialExtrapolator, SieveExtrapolator, WindowExtrapolator) from .potentials import (EnergySurface1DSpline, HarmonicPotential, MorsePotential, EnergySurfaceBase, PotentialBase, VibrationalStructureBase) +from .bopes_sampler import BOPESSampler __all__ = [ 'BOPESSampler', diff --git a/qiskit_nature/algorithms/pes_samplers/bopes_sampler.py b/qiskit_nature/algorithms/pes_samplers/bopes_sampler.py index c46d1fdbee..7ae26dd28d 100644 --- a/qiskit_nature/algorithms/pes_samplers/bopes_sampler.py +++ b/qiskit_nature/algorithms/pes_samplers/bopes_sampler.py @@ -17,13 +17,12 @@ import numpy as np from qiskit.algorithms import VariationalAlgorithm -from qiskit_nature.algorithms.ground_state_solvers import GroundStateSolver -from qiskit_nature.algorithms.pes_samplers.extrapolator import Extrapolator, WindowExtrapolator from qiskit_nature.drivers import BaseDriver from qiskit_nature.exceptions import QiskitNatureError from qiskit_nature.problems.second_quantization import BaseProblem -from qiskit_nature.results import EigenstateResult -from qiskit_nature.results.bopes_sampler_result import BOPESSamplerResult +from qiskit_nature.results import BOPESSamplerResult, EigenstateResult +from ..ground_state_solvers import GroundStateSolver +from .extrapolator import Extrapolator, WindowExtrapolator logger = logging.getLogger(__name__) diff --git a/qiskit_nature/algorithms/pes_samplers/potentials/energy_surface_spline.py b/qiskit_nature/algorithms/pes_samplers/potentials/energy_surface_spline.py index 6e7914d4f9..6edf740a66 100644 --- a/qiskit_nature/algorithms/pes_samplers/potentials/energy_surface_spline.py +++ b/qiskit_nature/algorithms/pes_samplers/potentials/energy_surface_spline.py @@ -18,7 +18,7 @@ from typing import Tuple, List, Optional, Callable, Any import scipy.interpolate as interp from scipy.optimize import minimize_scalar -from qiskit_nature.algorithms.pes_samplers.potentials.potential_base import EnergySurfaceBase +from .potential_base import EnergySurfaceBase class EnergySurface1DSpline(EnergySurfaceBase): diff --git a/qiskit_nature/circuit/__init__.py b/qiskit_nature/circuit/__init__.py index fd22d8d1f7..195f51888e 100644 --- a/qiskit_nature/circuit/__init__.py +++ b/qiskit_nature/circuit/__init__.py @@ -11,13 +11,11 @@ # that they have been altered from the originals. """ -Chemistry Circuits (:mod:`qiskit_nature.circuit`) -================================================= +Circuit library (:mod:`qiskit_nature.circuit`) +============================================== .. currentmodule:: qiskit_nature.circuit -Submodules -========== .. autosummary:: :toctree: diff --git a/qiskit_nature/circuit/library/__init__.py b/qiskit_nature/circuit/library/__init__.py index 7ba8716131..1aab82fce0 100644 --- a/qiskit_nature/circuit/library/__init__.py +++ b/qiskit_nature/circuit/library/__init__.py @@ -11,10 +11,10 @@ # that they have been altered from the originals. """ -Chemistry Circuit Library (:mod:`qiskit_nature.circuit.library`) -================================================================ +Circuit Library (:mod:`qiskit_nature.circuit.library`) +====================================================== -A collection of circuits used as building blocks or inputs of algorithms in chemistry. +A collection of circuits used as building blocks or inputs for algorithms. .. currentmodule:: qiskit_nature.circuit.library diff --git a/qiskit_nature/circuit/library/ansatzes/puccd.py b/qiskit_nature/circuit/library/ansatzes/puccd.py index fb1746d771..aaf84aa951 100644 --- a/qiskit_nature/circuit/library/ansatzes/puccd.py +++ b/qiskit_nature/circuit/library/ansatzes/puccd.py @@ -20,7 +20,7 @@ from qiskit.circuit import QuantumCircuit from qiskit_nature import QiskitNatureError -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .ucc import UCC from .utils.fermionic_excitation_generator import generate_fermionic_excitations diff --git a/qiskit_nature/circuit/library/ansatzes/succd.py b/qiskit_nature/circuit/library/ansatzes/succd.py index 553eca3535..3a2daa4e75 100644 --- a/qiskit_nature/circuit/library/ansatzes/succd.py +++ b/qiskit_nature/circuit/library/ansatzes/succd.py @@ -20,7 +20,7 @@ from qiskit.circuit import QuantumCircuit from qiskit_nature import QiskitNatureError -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .ucc import UCC from .utils.fermionic_excitation_generator import generate_fermionic_excitations diff --git a/qiskit_nature/circuit/library/ansatzes/ucc.py b/qiskit_nature/circuit/library/ansatzes/ucc.py index aadb649f6e..3264699855 100644 --- a/qiskit_nature/circuit/library/ansatzes/ucc.py +++ b/qiskit_nature/circuit/library/ansatzes/ucc.py @@ -22,7 +22,7 @@ from qiskit.opflow import PauliTrotterEvolution from qiskit_nature import QiskitNatureError from qiskit_nature.operators.second_quantization import FermionicOp, SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .evolved_operator_ansatz import EvolvedOperatorAnsatz from .utils.fermionic_excitation_generator import generate_fermionic_excitations diff --git a/qiskit_nature/circuit/library/ansatzes/uccsd.py b/qiskit_nature/circuit/library/ansatzes/uccsd.py index 3a4d94ee91..31b8cf4af1 100644 --- a/qiskit_nature/circuit/library/ansatzes/uccsd.py +++ b/qiskit_nature/circuit/library/ansatzes/uccsd.py @@ -18,7 +18,7 @@ import logging from qiskit.circuit import QuantumCircuit -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .ucc import UCC logger = logging.getLogger(__name__) diff --git a/qiskit_nature/circuit/library/ansatzes/uvcc.py b/qiskit_nature/circuit/library/ansatzes/uvcc.py index 8458152ed3..542093302b 100644 --- a/qiskit_nature/circuit/library/ansatzes/uvcc.py +++ b/qiskit_nature/circuit/library/ansatzes/uvcc.py @@ -21,7 +21,7 @@ from qiskit.opflow import PauliTrotterEvolution from qiskit_nature import QiskitNatureError from qiskit_nature.operators.second_quantization import SecondQuantizedOp, VibrationalOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .evolved_operator_ansatz import EvolvedOperatorAnsatz from .utils.vibration_excitation_generator import generate_vibration_excitations diff --git a/qiskit_nature/circuit/library/ansatzes/uvccsd.py b/qiskit_nature/circuit/library/ansatzes/uvccsd.py index 4ab81d27ec..08bb2fbfa2 100644 --- a/qiskit_nature/circuit/library/ansatzes/uvccsd.py +++ b/qiskit_nature/circuit/library/ansatzes/uvccsd.py @@ -18,7 +18,7 @@ import logging from qiskit.circuit import QuantumCircuit -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from .uvcc import UVCC logger = logging.getLogger(__name__) diff --git a/qiskit_nature/circuit/library/initial_states/hartree_fock.py b/qiskit_nature/circuit/library/initial_states/hartree_fock.py index 42c3e09ca1..5630d0f14a 100644 --- a/qiskit_nature/circuit/library/initial_states/hartree_fock.py +++ b/qiskit_nature/circuit/library/initial_states/hartree_fock.py @@ -21,7 +21,7 @@ from qiskit.utils.validation import validate_min from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter class HartreeFock(QuantumCircuit): diff --git a/qiskit_nature/circuit/library/initial_states/vscf.py b/qiskit_nature/circuit/library/initial_states/vscf.py index ab9d61d9ee..c40a6e6dfb 100644 --- a/qiskit_nature/circuit/library/initial_states/vscf.py +++ b/qiskit_nature/circuit/library/initial_states/vscf.py @@ -20,9 +20,9 @@ from qiskit import QuantumRegister, QuantumCircuit from qiskit.opflow import PauliSumOp -from qiskit_nature.mappers.second_quantization.direct_mapper import DirectMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.operators.second_quantization.vibrational_op import VibrationalOp +from qiskit_nature.mappers.second_quantization import DirectMapper +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.operators.second_quantization import VibrationalOp logger = logging.getLogger(__name__) diff --git a/qiskit_nature/converters/__init__.py b/qiskit_nature/converters/__init__.py new file mode 100644 index 0000000000..8d0ce1192c --- /dev/null +++ b/qiskit_nature/converters/__init__.py @@ -0,0 +1,23 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2021. +# +# 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. + +""" +Operator to Qubit Operator Converters (:mod:`qiskit_nature.converters`) +======================================================================= + +.. currentmodule:: qiskit_nature.converters + +.. autosummary:: + :toctree: + + second_quantization +""" diff --git a/qiskit_nature/converters/second_quantization/__init__.py b/qiskit_nature/converters/second_quantization/__init__.py new file mode 100644 index 0000000000..7641e2d24e --- /dev/null +++ b/qiskit_nature/converters/second_quantization/__init__.py @@ -0,0 +1,35 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2021. +# +# 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. + +""" +SecondQuantizedOp Converters (:mod:`qiskit_nature.converters.second_quantization`) +================================================================================== + +.. currentmodule:: qiskit_nature.converters.second_quantization + +The classes here are used to convert fermionic, vibrational and spin operators to qubit operators, +using mappers and other techniques that can also reduce the problem such as leveraging +Z2 Symmetries. + +.. autosummary:: + :toctree: ../stubs/ + :nosignatures: + + QubitConverter + +""" + +from .qubit_converter import QubitConverter + +__all__ = [ + 'QubitConverter', +] diff --git a/qiskit_nature/converters/second_quantization/qubit_converter.py b/qiskit_nature/converters/second_quantization/qubit_converter.py new file mode 100644 index 0000000000..d4d5927ceb --- /dev/null +++ b/qiskit_nature/converters/second_quantization/qubit_converter.py @@ -0,0 +1,362 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2021. +# +# 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. + +"""A converter from Second-Quantized to Qubit Operators.""" +import copy +import logging +from typing import cast, Callable, List, Optional, Tuple, Union + +import numpy as np + +from qiskit.opflow import PauliSumOp +from qiskit.opflow.converters import TwoQubitReduction +from qiskit.opflow.primitive_ops import Z2Symmetries + +from qiskit_nature import QiskitNatureError +from qiskit_nature.mappers.second_quantization import QubitMapper + +from qiskit_nature.operators.second_quantization import SecondQuantizedOp + +logger = logging.getLogger(__name__) + + +class QubitConverter: + """A converter from Second-Quantized to Qubit Operators. + + This converter can be configured with a mapper instance which will later be used + when 2nd quantized operators are requested to be converted (mapped) to qubit operators. + + For a Fermionic system, when its a electronic problem, there are certain mappers, such as + the :class:`~qiskit_nature.mappers.second_quantization.ParityMapper` that introduces known + symmetries, by virtue of the mapping, that can be exploited to reduce the size of the + problem, i.e the qubit operator, by two qubits. The two qubit reduction setting indicates + to do this where possible - i.e. mapper supports it and the number of particles in the + Fermionic system is provided for the conversion. (The number of particles is used to + determine the symmetry) + + Also this converter supports Z2 Symmetry reduction to reduce a problem (operator) size + based on mathematical symmetries that can be detected in the operator. A knowledgeable user + can define which sector the problem solution lies in. This sector information can also + be passed in on :meth:`convert` which will override this value should both be given. + """ + + def __init__(self, + mapper: QubitMapper, + two_qubit_reduction: bool = False, + z2symmetry_reduction: Optional[Union[str, List[int]]] = None): + """ + + Args: + mapper: A mapper instance used to convert second quantized to qubit operators + two_qubit_reduction: Whether to carry out two qubit reduction when possible + z2symmetry_reduction: Indicates whether a z2 symmetry reduction should be applied to + resulting qubit operators that are computed. For each symmetry detected the operator + will be split into two where each requires one qubit less for computation. So for + example 3 symmetries will split the original operator into 8 new operators each + requiring 3 less qubits. Now only one of these operators will have the ground state + and be the correct symmetry sector needed for the ground state. Setting 'auto' will + use an automatic computation of the correct sector. If the sector is known + from other experiments with the z2symmetry logic, then the tapering values of that + sector can be provided (a list of int of values -1, and 1). The default is None + meaning no symmetry reduction is done. + """ + + self._mapper: QubitMapper = mapper + self._two_qubit_reduction: bool = two_qubit_reduction + self._z2symmetry_reduction: Optional[Union[str, List[int]]] = None + self.z2symmetry_reduction = z2symmetry_reduction # Setter does validation + + self._did_two_qubit_reduction: bool = False + self._num_particles: Optional[Tuple[int, int]] = None + self._z2symmetries: Z2Symmetries = self._no_symmetries + + @property + def _no_symmetries(self) -> Z2Symmetries: + return Z2Symmetries([], [], [], None) + + @property + def mapper(self) -> QubitMapper: + """Get mapper""" + return self._mapper + + @mapper.setter + def mapper(self, value: QubitMapper) -> None: + """Set mapper""" + self._mapper = value + self._z2symmetries = None # Reset as symmetries my change due to mapper change + + @property + def two_qubit_reduction(self) -> bool: + """Get two_qubit_reduction""" + return self._two_qubit_reduction + + @two_qubit_reduction.setter + def two_qubit_reduction(self, value: bool) -> None: + """Set two_qubit_reduction""" + self._two_qubit_reduction = value + self._z2symmetries = None # Reset as symmetries my change due to this reduction + + @property + def z2symmetry_reduction(self) -> Optional[Union[str, List[int]]]: + """Get z2symmetry_reduction""" + return self._z2symmetry_reduction + + @z2symmetry_reduction.setter + def z2symmetry_reduction(self, z2symmetry_reduction: Optional[Union[str, List[int]]]) -> None: + """Set z2symmetry_reduction""" + if z2symmetry_reduction is not None: + if isinstance(z2symmetry_reduction, str): + if z2symmetry_reduction != 'auto': + raise ValueError("The only string-like option for z2symmetry_reduction is " + "'auto', not {}".format(z2symmetry_reduction)) + elif not np.all(np.isin(z2symmetry_reduction, [-1, 1])): + raise ValueError('z2symmetry_reduction tapering values list must ' + 'contain -1\'s and/or 1\'s only but was {}'. + format(z2symmetry_reduction)) + + self._z2symmetry_reduction = z2symmetry_reduction + + @property + def num_particles(self) -> Optional[Tuple[int, int]]: + """Get the number of particles as supplied to :meth:`convert`. + + This can also be set, for advanced usage, using :meth:`force_match` + """ + return self._num_particles + + @property + def z2symmetries(self) -> Z2Symmetries: + """Get Z2Symmetries as detected from conversion via :meth:`convert`. + + This may indicate no symmetries, i.e. be empty, if none were detected. + + This can also be set, for advanced usage, using :meth:`force_match` + """ + return copy.deepcopy(self._z2symmetries) + + def convert(self, second_q_op: SecondQuantizedOp, + num_particles: Optional[Tuple[int, int]] = None, + sector_locator: Optional[Callable[[Z2Symmetries], Optional[List[int]]]] = None + ) -> PauliSumOp: + """ + Map the given second quantized operator to a qubit operators. Also it will + carry out z2 symmetry reduction on the qubit operators if z2symmetry_reduction has + been specified whether via the constructor or indirectly via the sector locator which + is passed the detected symmetries to inform the determination. + + Args: + second_q_op: A second quantized operator. + num_particles: Needed for two qubit reduction to determine correct sector. If + not supplied, even if two_qubit_reduction is possible, it will not be done. + sector_locator: An optional callback, that given the detected Z2Symmetries can + determine the correct sector of the tapered operators so the correct one + can be returned, which contains the problem solution, out of the set that are + the result of tapering. + + Returns: + PauliSumOp qubit operator + """ + qubit_op = self._map(second_q_op) + reduced_op = self._two_qubit_reduce(qubit_op, num_particles) + tapered_op, z2symmetries = self._find_taper_op(reduced_op, sector_locator) + + self._num_particles = num_particles + self._z2symmetries = z2symmetries + + return tapered_op + + def force_match(self, num_particles: Optional[Tuple[int, int]] = None, + z2symmetries: Optional[Z2Symmetries] = None) -> None: + """ This is for advanced use where :meth:`convert` may not have been called or the + converter should be used to taper to some external characteristics to be matched + when using :meth:`convert_match`. Parameters passed here, when not None, + will override any values stored from :meth:`convert`. + + Args: + num_particles: The number or particles pertaining to two qubit reduction + z2symmetries: Z2Symmetry information for tapering + + Raises: + ValueError: If format of Z2Symmetry tapering values is invalid + """ + if num_particles is not None: + self._num_particles = num_particles + + if z2symmetries is not None: + if not z2symmetries.is_empty(): + if len(z2symmetries.tapering_values) != len(z2symmetries.sq_list): + raise ValueError(f'Z2Symmetries tapering value length was ' + f'{len(z2symmetries.tapering_values)} but expected ' + f'{len(z2symmetries.sq_list)}.') + if not np.all(np.isin(z2symmetries.tapering_values, [-1, 1])): + raise ValueError(f'Z2Symmetries values list must contain only ' + f'-1\'s and/or 1\'s but was {z2symmetries.tapering_values}.') + + self._z2symmetries = z2symmetries + + def convert_match(self, second_q_ops: Union[SecondQuantizedOp, List[SecondQuantizedOp]], + suppress_none: bool = False + ) -> Union[PauliSumOp, List[Optional[PauliSumOp]]]: + """ Convert further operators to match that done in :meth:`convert`, or as set by + :meth:`force_match`. + + Args: + second_q_ops: A second quantized operator or list thereof to be converted + suppress_none: If None should be placed in the output list where an operator + did not commute with symmetry, to maintain order, or whether that should + be suppressed where the output list length may then be smaller than the input + + Returns: + A qubit operator or list thereof of the same length as the second_q_ops list. All + operators in the second_q_ops list must commute with the symmetry detected when + :meth:`convert` was called. If it does not then the position in the output list + will be set to `None` to preserve the order, unless suppress_none is set; or None may + be directly returned in the case when a single operator is provided (that cannot be + suppressed as it's a single value) + """ + # To allow a single operator to be converted, but use the same logic that does the + # actual conversions, we make a single entry list of it here and unwrap to return. + wrapped = False + if isinstance(second_q_ops, SecondQuantizedOp): + second_q_ops = [second_q_ops] + wrapped = True + suppress_none = False # When only a single op we will return None back + + qubit_ops = [self._map(second_q_op) for second_q_op in second_q_ops] + reduced_ops = [self._two_qubit_reduce(qubit_op, self._num_particles) + for qubit_op in qubit_ops] + tapered_ops = self._symmetry_reduce(reduced_ops, suppress_none) + + if wrapped: + tapered_ops = tapered_ops[0] + + return tapered_ops + + def map(self, second_q_ops: Union[SecondQuantizedOp, List[SecondQuantizedOp]]) \ + -> Union[PauliSumOp, List[Optional[PauliSumOp]]]: + """ A convenience method to map second quantized operators based on current mapper. + + Args: + second_q_ops: A second quantized operator, or list thereof + + Returns: + A qubit operator in the form of a PauliSumOp, or list thereof if a list of + second quantized operators was supplied + """ + if isinstance(second_q_ops, SecondQuantizedOp): + qubit_ops = self._map(second_q_ops) + else: + qubit_ops = [self._map(second_q_op) for second_q_op in second_q_ops] + + return qubit_ops + + def _map(self, second_q_op: SecondQuantizedOp) -> PauliSumOp: + return self._mapper.map(second_q_op) + + def _two_qubit_reduce(self, qubit_op: PauliSumOp, + num_particles: Optional[Tuple[int, int]]) -> PauliSumOp: + reduced_op = qubit_op + + if num_particles is not None: + if self._two_qubit_reduction and self._mapper.allows_two_qubit_reduction: + two_q_reducer = TwoQubitReduction(num_particles) + reduced_op = cast(PauliSumOp, two_q_reducer.convert(qubit_op)) + + return reduced_op + + def _find_taper_op(self, qubit_op: PauliSumOp, + sector_locator: Optional[Callable[[Z2Symmetries], + Optional[List[int]]]] = None + ) -> Tuple[PauliSumOp, Z2Symmetries]: + # Return operator unchanged and empty symmetries if we do not taper + tapered_qubit_op = qubit_op + z2_symmetries = self._no_symmetries + + # If we were given a sector, or one might be located, we first need to find any symmetries + if self.z2symmetry_reduction is not None: + z2_symmetries = Z2Symmetries.find_Z2_symmetries(qubit_op) + if z2_symmetries.is_empty(): + logger.debug('No Z2 symmetries found') + else: + # As we have symmetries, if we have a sector locator, if that provides one back + # it will override any value defined on constructor + if sector_locator is not None and self.z2symmetry_reduction == 'auto': + z2symmetry_reduction = sector_locator(z2_symmetries) + if z2symmetry_reduction is not None: + self.z2symmetry_reduction = z2symmetry_reduction # Overrides any value + + # We may end up that neither were we given a sector nor that the locator + # returned one. Since though we may have found valid symmetries above we should + # simply just forget about them so as not to return something we are not using. + if self.z2symmetry_reduction is None: + z2_symmetries = self._no_symmetries + + # So now if we have a sector and have symmetries we found we can attempt to taper + if self.z2symmetry_reduction is not None and self.z2symmetry_reduction != 'auto' \ + and not z2_symmetries.is_empty(): + # check sector definition fits to symmetries found + if len(self._z2symmetry_reduction) != len(z2_symmetries.symmetries): + raise QiskitNatureError('z2symmetry_reduction tapering values list has ' + 'invalid length {} should be {}'. + format(len(self._z2symmetry_reduction), + len(z2_symmetries.symmetries))) + # Check all operators commute with main operator's symmetry + logger.debug('Sanity check that operator commutes with the symmetry') + symmetry_ops = [] + for symmetry in z2_symmetries.symmetries: + symmetry_ops.append(PauliSumOp.from_list([(symmetry.to_label(), 1.0)])) + commutes = QubitConverter._check_commutes(symmetry_ops, qubit_op) + if not commutes: + raise QiskitNatureError('Z2 symmetry failure. The operator must commute ' + 'with symmetries found from it!') + + z2_symmetries.tapering_values = self._z2symmetry_reduction + tapered_qubit_op = z2_symmetries.taper(qubit_op) if commutes else None + + return tapered_qubit_op, z2_symmetries + + def _symmetry_reduce(self, qubit_ops: List[PauliSumOp], + suppress_none: bool) -> List[Optional[PauliSumOp]]: + + if self._z2symmetries is None or self._z2symmetries.is_empty(): + tapered_qubit_ops = qubit_ops + else: + logger.debug('Checking operators commute with symmetry:') + symmetry_ops = [] + for symmetry in self._z2symmetries.symmetries: + symmetry_ops.append(PauliSumOp.from_list([(symmetry.to_label(), 1.0)])) + commuted = [] + for i, qubit_op in enumerate(qubit_ops): + commutes = QubitConverter._check_commutes(symmetry_ops, qubit_op) + commuted.append(commutes) + logger.debug("Qubit operators commuted with symmetry %s", commuted) + + # Tapering values were set from prior convert so we go ahead and taper operators + tapered_qubit_ops = [] + for i, commutes in enumerate(commuted): + if commutes: + tapered_qubit_ops.append(self._z2symmetries.taper(qubit_ops[i])) + elif not suppress_none: + tapered_qubit_ops.append(None) + + return tapered_qubit_ops + + @staticmethod + def _check_commutes(cliffords: List[PauliSumOp], qubit_op: PauliSumOp) -> bool: + commutes = [] + for clifford in cliffords: + commuting_rows = qubit_op.primitive.table.commutes_with_all(clifford.primitive.table) + commutes.append(len(commuting_rows) == qubit_op.primitive.size) + does_commute = bool(np.all(commutes)) + logger.debug(' \'%s\' commutes: %s, %s', id(qubit_op), does_commute, commutes) + + return does_commute diff --git a/qiskit_nature/drivers/__init__.py b/qiskit_nature/drivers/__init__.py index 41932ad88b..1bbeb6a642 100644 --- a/qiskit_nature/drivers/__init__.py +++ b/qiskit_nature/drivers/__init__.py @@ -15,13 +15,13 @@ ================================================ .. currentmodule:: qiskit_nature.drivers -Qiskit's chemistry module requires a computational chemistry program or library, accessed via a +Qiskit Nature requires a computational chemistry program or library, accessed via a chemistry *driver*, to be installed on the system for the electronic-structure computation of a given molecule. A driver is created with a molecular configuration, passed in the format compatible with that particular driver. This allows custom configuration specific to each computational chemistry program or library to be passed. -The chemistry module thus allows the user to configure a chemistry problem in a way that a chemist +Qiskit Nature thus allows the user to configure a chemistry problem in a way that a chemist already using the underlying chemistry program or library will be familiar with. The driver is used to compute some intermediate data, which later will be used to form the input to an algorithm. Such intermediate data, is populated into a :class:`~qiskit_nature.drivers.QMolecule` @@ -37,7 +37,7 @@ used to compute it. However the values and level of accuracy of such data will depend on the underlying chemistry program or library used by the specific driver. -Qiskit's chemistry module offers the option to serialize the Qmolecule data in a binary format known +Qiskit Nature offers the option to serialize the Qmolecule data in a binary format known as `Hierarchical Data Format 5 (HDF5) `__. This is done to allow chemists to reuse the same input data in the future and to enable researchers to exchange input data with each other --- which is especially useful to researchers who may not diff --git a/qiskit_nature/drivers/gaussiand/gaussiandriver.py b/qiskit_nature/drivers/gaussiand/gaussiandriver.py index 7ac677ee20..7ccc930f24 100644 --- a/qiskit_nature/drivers/gaussiand/gaussiandriver.py +++ b/qiskit_nature/drivers/gaussiand/gaussiandriver.py @@ -54,14 +54,16 @@ def __init__(self, """ Args: config: A molecular configuration conforming to Gaussian™ 16 format. - molecule: A driver independent Molecule definition instance may be provided. When - a molecule is supplied the `config` parameter is ignored and the Molecule instance, - along with `basis` and `hf_method` is used to build a basic config instead. + molecule: A driver independent Molecule definition instance may be provided. When a + molecule is supplied the ``config`` parameter is ignored and the Molecule instance, + along with ``basis`` and ``hf_method`` is used to build a basic config instead. The Molecule object is read when the driver is run and converted to the driver dependent configuration for the computation. This allows, for example, the Molecule geometry to be updated to compute different points. - basis: Basis set - hf_method: Hartree-Fock Method type + basis: Basis set name as recognized by Gaussian™ 16. + See https://gaussian.com/basissets/ for more information. + Defaults to the minimal basis 'sto-3g'. + hf_method: Hartree-Fock Method type. Raises: QiskitNatureError: Invalid Input diff --git a/qiskit_nature/drivers/psi4d/psi4driver.py b/qiskit_nature/drivers/psi4d/psi4driver.py index cc180772b1..146edb950a 100644 --- a/qiskit_nature/drivers/psi4d/psi4driver.py +++ b/qiskit_nature/drivers/psi4d/psi4driver.py @@ -50,14 +50,16 @@ def __init__(self, """ Args: config: A molecular configuration conforming to PSI4 format. - molecule: A driver independent Molecule definition instance may be provided. When - a molecule is supplied the `config` parameter is ignored and the Molecule instance, - along with `basis` and `hf_method` is used to build a basic config instead. + molecule: A driver independent Molecule definition instance may be provided. When a + molecule is supplied the ``config`` parameter is ignored and the Molecule instance, + along with ``basis`` and ``hf_method`` is used to build a basic config instead. The Molecule object is read when the driver is run and converted to the driver dependent configuration for the computation. This allows, for example, the Molecule geometry to be updated to compute different points. - basis: Basis set - hf_method: Hartree-Fock Method type + basis: Basis set name as recognized by the PSI4 program. + See https://psicode.org/psi4manual/master/basissets.html for more information. + Defaults to the minimal basis 'sto-3g'. + hf_method: Hartree-Fock Method type. Raises: QiskitNatureError: Invalid Input diff --git a/qiskit_nature/drivers/pyquanted/pyquantedriver.py b/qiskit_nature/drivers/pyquanted/pyquantedriver.py index 02dc7aeec3..0c26a97ef6 100644 --- a/qiskit_nature/drivers/pyquanted/pyquantedriver.py +++ b/qiskit_nature/drivers/pyquanted/pyquantedriver.py @@ -59,18 +59,18 @@ def __init__(self, atoms: Atoms list or string separated by semicolons or line breaks. Each element in the list is an atom followed by position e.g. `H 0.0 0.0 0.5`. The preceding example shows the `XYZ` format for position but `Z-Matrix` format is supported too here. - units: Angstrom or Bohr - charge: Charge on the molecule + units: Angstrom or Bohr. + charge: Charge on the molecule. multiplicity: Spin multiplicity (2S+1) basis: Basis set; sto3g, 6-31g or 6-31g** - hf_method: Hartree-Fock Method type + hf_method: Hartree-Fock Method type. tol: Convergence tolerance see pyquante2.scf hamiltonians and iterators maxiters: Convergence max iterations see pyquante2.scf hamiltonians and iterators, has a min. value of 1. - molecule: A driver independent Molecule definition instance may be provided. When - a molecule is supplied the `atoms`, `units`, `charge` and `multiplicity` parameters - are all ignored as the Molecule instance now defines these instead. The Molecule - object is read when the driver is run and converted to the driver dependent + molecule: A driver independent Molecule definition instance may be provided. When a + molecule is supplied the ``atoms``, ``units``, ``charge`` and ``multiplicity`` + parameters are all ignored as the Molecule instance now defines these instead. The + Molecule object is read when the driver is run and converted to the driver dependent configuration for the computation. This allows, for example, the Molecule geometry to be updated to compute different points. diff --git a/qiskit_nature/drivers/pyscfd/pyscfdriver.py b/qiskit_nature/drivers/pyscfd/pyscfdriver.py index e0b57c7af3..988ff54c76 100644 --- a/qiskit_nature/drivers/pyscfd/pyscfdriver.py +++ b/qiskit_nature/drivers/pyscfd/pyscfdriver.py @@ -65,7 +65,9 @@ def __init__(self, unit: Angstrom or Bohr charge: Charge on the molecule spin: Spin (2S), in accordance with how PySCF defines a molecule in pyscf.gto.mole.Mole - basis: Basis set + basis: Basis set name as recognized by PySCF, e.g. `sto3g`, `321g` etc. + See https://sunqm.github.io/pyscf/_modules/pyscf/gto/basis.html for a listing. + Defaults to the minimal basis 'sto3g'. hf_method: Hartree-Fock Method type conv_tol: Convergence tolerance see PySCF docs and pyscf/scf/hf.py max_cycle: Max convergence cycles see PySCF docs and pyscf/scf/hf.py, @@ -73,7 +75,7 @@ def __init__(self, init_guess: See PySCF pyscf/scf/hf.py init_guess_by_minao/1e/atom methods max_memory: Maximum memory that PySCF should use molecule: A driver independent Molecule definition instance may be provided. When - a molecule is supplied the `atom`, `unit`, `charge` and `spin` parameters + a molecule is supplied the ``atom``, ``unit``, ``charge`` and ``spin`` parameters are all ignored as the Molecule instance now defines these instead. The Molecule object is read when the driver is run and converted to the driver dependent configuration for the computation. This allows, for example, the Molecule geometry diff --git a/qiskit_nature/mappers/__init__.py b/qiskit_nature/mappers/__init__.py index 3514360d19..2b51319fd5 100644 --- a/qiskit_nature/mappers/__init__.py +++ b/qiskit_nature/mappers/__init__.py @@ -17,31 +17,8 @@ .. currentmodule:: qiskit_nature.mappers - -Second-Quantization Mappers -+++++++++++++++++++++++++++ - .. autosummary:: - :toctree: ../stubs/ - - BravyiKitaevMapper - DirectMapper - JordanWignerMapper - LinearMapper - ParityMapper + :toctree: + second_quantization """ - -from .second_quantization import BravyiKitaevMapper -from .second_quantization import DirectMapper -from .second_quantization import JordanWignerMapper -from .second_quantization import LinearMapper -from .second_quantization import ParityMapper - -__all__ = [ - "BravyiKitaevMapper", - "DirectMapper", - "JordanWignerMapper", - "LinearMapper", - "ParityMapper", -] diff --git a/qiskit_nature/mappers/second_quantization/__init__.py b/qiskit_nature/mappers/second_quantization/__init__.py index 8163701707..69077750d6 100644 --- a/qiskit_nature/mappers/second_quantization/__init__.py +++ b/qiskit_nature/mappers/second_quantization/__init__.py @@ -16,6 +16,13 @@ .. currentmodule:: qiskit_nature.mappers.second_quantization +The classes here are used to convert fermionic, vibrational and spin operators to qubit operators. + +.. autosummary:: + :toctree: ../stubs/ + :nosignatures: + + QubitMapper FermionicOp Mappers +++++++++++++++++++ @@ -24,6 +31,7 @@ :toctree: ../stubs/ :nosignatures: + FermionicMapper BravyiKitaevMapper JordanWignerMapper ParityMapper @@ -36,6 +44,7 @@ :toctree: ../stubs/ :nosignatures: + VibrationalMapper DirectMapper @@ -46,6 +55,7 @@ :toctree: ../stubs/ :nosignatures: + SpinMapper LinearMapper """ diff --git a/qiskit_nature/mappers/second_quantization/bravyi_kitaev_mapper.py b/qiskit_nature/mappers/second_quantization/bravyi_kitaev_mapper.py index 89c6c72796..9a18eb3b77 100644 --- a/qiskit_nature/mappers/second_quantization/bravyi_kitaev_mapper.py +++ b/qiskit_nature/mappers/second_quantization/bravyi_kitaev_mapper.py @@ -17,7 +17,7 @@ from qiskit.opflow import PauliSumOp from qiskit.quantum_info.operators import Pauli -from qiskit_nature.operators.second_quantization.fermionic_op import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from .fermionic_mapper import FermionicMapper from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/mappers/second_quantization/fermionic_mapper.py b/qiskit_nature/mappers/second_quantization/fermionic_mapper.py index a331028833..62b40f59f9 100644 --- a/qiskit_nature/mappers/second_quantization/fermionic_mapper.py +++ b/qiskit_nature/mappers/second_quantization/fermionic_mapper.py @@ -15,7 +15,7 @@ from abc import abstractmethod from qiskit.opflow import PauliSumOp -from qiskit_nature.operators import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/mappers/second_quantization/jordan_wigner_mapper.py b/qiskit_nature/mappers/second_quantization/jordan_wigner_mapper.py index d0f82643fa..b9deaea422 100644 --- a/qiskit_nature/mappers/second_quantization/jordan_wigner_mapper.py +++ b/qiskit_nature/mappers/second_quantization/jordan_wigner_mapper.py @@ -17,7 +17,7 @@ from qiskit.opflow import PauliSumOp from qiskit.quantum_info.operators import Pauli -from qiskit_nature.operators.second_quantization.fermionic_op import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from .fermionic_mapper import FermionicMapper from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/mappers/second_quantization/linear_mapper.py b/qiskit_nature/mappers/second_quantization/linear_mapper.py index 0b99735049..c862456476 100644 --- a/qiskit_nature/mappers/second_quantization/linear_mapper.py +++ b/qiskit_nature/mappers/second_quantization/linear_mapper.py @@ -22,7 +22,7 @@ from qiskit.opflow import PauliSumOp from qiskit.quantum_info.operators import Pauli, SparsePauliOp -from qiskit_nature.operators.second_quantization.spin_op import SpinOp +from qiskit_nature.operators.second_quantization import SpinOp from .spin_mapper import SpinMapper diff --git a/qiskit_nature/mappers/second_quantization/parity_mapper.py b/qiskit_nature/mappers/second_quantization/parity_mapper.py index 8bc88a0080..fde4723d19 100644 --- a/qiskit_nature/mappers/second_quantization/parity_mapper.py +++ b/qiskit_nature/mappers/second_quantization/parity_mapper.py @@ -18,7 +18,7 @@ from qiskit.opflow import PauliSumOp from qiskit.quantum_info.operators import Pauli -from qiskit_nature.operators.second_quantization.fermionic_op import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from .fermionic_mapper import FermionicMapper from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/mappers/second_quantization/spin_mapper.py b/qiskit_nature/mappers/second_quantization/spin_mapper.py index 39d6bd0db2..337235953b 100644 --- a/qiskit_nature/mappers/second_quantization/spin_mapper.py +++ b/qiskit_nature/mappers/second_quantization/spin_mapper.py @@ -15,7 +15,7 @@ from abc import abstractmethod from qiskit.opflow import PauliSumOp -from qiskit_nature.operators import SpinOp +from qiskit_nature.operators.second_quantization import SpinOp from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/mappers/second_quantization/vibrational_mapper.py b/qiskit_nature/mappers/second_quantization/vibrational_mapper.py index d761211456..b03dc795e7 100644 --- a/qiskit_nature/mappers/second_quantization/vibrational_mapper.py +++ b/qiskit_nature/mappers/second_quantization/vibrational_mapper.py @@ -15,7 +15,7 @@ from abc import abstractmethod from qiskit.opflow import PauliSumOp -from qiskit_nature.operators import VibrationalOp +from qiskit_nature.operators.second_quantization import VibrationalOp from .qubit_mapper import QubitMapper diff --git a/qiskit_nature/operators/__init__.py b/qiskit_nature/operators/__init__.py index 4411e71292..8b2d88a46c 100644 --- a/qiskit_nature/operators/__init__.py +++ b/qiskit_nature/operators/__init__.py @@ -11,31 +11,16 @@ # that they have been altered from the originals. """ -Operators for Qiskit Nature (:mod:`qiskit_nature.operators`) -============================================================ +Operators (:mod:`qiskit_nature.operators`) +========================================== .. currentmodule:: qiskit_nature.operators -Operators -========== - -Second-Quantization Operators -+++++++++++++++++++++++++++++ +Operators for different systems such as fermionic, vibrational and spin. .. autosummary:: - :toctree: ../stubs/ - - FermionicOp - SpinOp - VibrationalOp -""" + :toctree: -from .second_quantization import FermionicOp -from .second_quantization import SpinOp -from .second_quantization import VibrationalOp + second_quantization -__all__ = [ - 'FermionicOp', - 'SpinOp', - 'VibrationalOp', -] +""" diff --git a/qiskit_nature/operators/second_quantization/__init__.py b/qiskit_nature/operators/second_quantization/__init__.py index a9ca382837..f07878f56e 100644 --- a/qiskit_nature/operators/second_quantization/__init__.py +++ b/qiskit_nature/operators/second_quantization/__init__.py @@ -11,8 +11,8 @@ # that they have been altered from the originals. """ -Second-Quantization Operators for Qiskit Nature (:mod:`qiskit_nature.operators.second_quantization`) -==================================================================================================== +Second-Quantization Operators (:mod:`qiskit_nature.operators.second_quantization`) +================================================================================== .. currentmodule:: qiskit_nature.operators.second_quantization diff --git a/qiskit_nature/operators/second_quantization/fermionic_op.py b/qiskit_nature/operators/second_quantization/fermionic_op.py index 935cfb481d..63e45d8279 100644 --- a/qiskit_nature/operators/second_quantization/fermionic_op.py +++ b/qiskit_nature/operators/second_quantization/fermionic_op.py @@ -19,7 +19,7 @@ from qiskit.utils.validation import validate_min, validate_range_exclusive_max from qiskit_nature import QiskitNatureError -from qiskit_nature.operators.second_quantization.second_quantized_op import SecondQuantizedOp +from .second_quantized_op import SecondQuantizedOp class FermionicOp(SecondQuantizedOp): @@ -111,7 +111,7 @@ class FermionicOp(SecondQuantizedOp): .. jupyter-execute:: - from qiskit_nature.operators import FermionicOp + from qiskit_nature.operators.second_quantization import FermionicOp 0.5 * FermionicOp("I+") + FermionicOp("+I") Sum diff --git a/qiskit_nature/operators/second_quantization/qubit_converter.py b/qiskit_nature/operators/second_quantization/qubit_converter.py index 664c6a402f..1c76921bee 100644 --- a/qiskit_nature/operators/second_quantization/qubit_converter.py +++ b/qiskit_nature/operators/second_quantization/qubit_converter.py @@ -11,8 +11,10 @@ # that they have been altered from the originals. """A converter from Second-Quantized to Qubit Operators.""" + import copy import logging +import warnings from typing import cast, Callable, List, Optional, Tuple, Union import numpy as np @@ -24,13 +26,15 @@ from qiskit_nature import QiskitNatureError from qiskit_nature.mappers.second_quantization import QubitMapper -from . import SecondQuantizedOp +from qiskit_nature.operators.second_quantization import SecondQuantizedOp logger = logging.getLogger(__name__) class QubitConverter: - """A converter from Second-Quantized to Qubit Operators. + """ **DEPRECATED** A converter from Second-Quantized to Qubit Operators. + + The QubitConverter was moved to `converters.second_quantization` package. This converter can be configured with a mapper instance which will later be used when 2nd quantized operators are requested to be converted (mapped) to qubit operators. @@ -69,6 +73,11 @@ def __init__(self, sector can be provided (a list of int of values -1, and 1). The default is None meaning no symmetry reduction is done. """ + warnings.warn('This QubitConverter is deprecated as of 0.1.0, ' + 'and will be removed no earlier than 3 months after the release. ' + 'You should use the qiskit_nature.converters.second_quantization ' + 'QubitConverter as a direct replacement instead.', + DeprecationWarning, stacklevel=2) self._mapper: QubitMapper = mapper self._two_qubit_reduction: bool = two_qubit_reduction diff --git a/qiskit_nature/operators/second_quantization/spin_op.py b/qiskit_nature/operators/second_quantization/spin_op.py index 04713380a6..36c5d5b377 100644 --- a/qiskit_nature/operators/second_quantization/spin_op.py +++ b/qiskit_nature/operators/second_quantization/spin_op.py @@ -116,7 +116,7 @@ class SpinOp(SecondQuantizedOp): .. jupyter-execute:: - from qiskit_nature.operators import SpinOp + from qiskit_nature.operators.second_quantization import SpinOp x = SpinOp("X", spin=3/2) y = SpinOp("Y", spin=3/2) diff --git a/qiskit_nature/problems/__init__.py b/qiskit_nature/problems/__init__.py index e58e63903e..d12db547d4 100644 --- a/qiskit_nature/problems/__init__.py +++ b/qiskit_nature/problems/__init__.py @@ -11,24 +11,15 @@ # that they have been altered from the originals. """ -Nature Science Problems (:mod:`qiskit_nature.problems`) -======================================================= +Problems (:mod:`qiskit_nature.problems`) +======================================== .. currentmodule:: qiskit_nature.problems -Second-Quantization Problems -++++++++++++++++++++++++++++ - .. autosummary:: - :toctree: ../stubs/ - -""" + :toctree: -from .second_quantization import ElectronicStructureProblem -from .second_quantization import VibrationalStructureProblem + second_quantization -__all__ = [ - "ElectronicStructureProblem", - "VibrationalStructureProblem", -] +""" diff --git a/qiskit_nature/problems/second_quantization/base_problem.py b/qiskit_nature/problems/second_quantization/base_problem.py index 2f45eb0a82..320814a377 100644 --- a/qiskit_nature/problems/second_quantization/base_problem.py +++ b/qiskit_nature/problems/second_quantization/base_problem.py @@ -20,7 +20,7 @@ from qiskit.opflow import PauliSumOp, Z2Symmetries from qiskit_nature.drivers import BaseDriver, QMolecule, WatsonHamiltonian -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.results import EigenstateResult from qiskit_nature.transformers import BaseTransformer @@ -128,13 +128,14 @@ def hopping_qeom_ops(self, qubit_converter: QubitConverter, Z2 symmetries stored in this instance are the basis for the commutativity information returned by this method. excitations: the types of excitations to consider. The simple cases for this input are: - - a `str` containing any of the following characters: `s`, `d`, `t` or `q`. - - a single, positive `int` denoting the excitation type (1 == `s`, etc.). - - a list of positive integers. - - and finally a callable which can be used to specify a custom list of excitations. - For more details on how to write such a function refer to one of the default - methods, :meth:`generate_fermionic_excitations` or - :meth:`generate_vibrational_excitations`. + + :`str`: containing any of the following characters: `s`, `d`, `t` or `q`. + :`int`: a single, positive integer denoting the excitation type (1 == `s`, etc.). + :`List[int]`: a list of positive integers. + :`Callable`: a function which is used to generate the excitations. + For more details on how to write such a function refer to one of the default + methods, :meth:`generate_fermionic_excitations` or + :meth:`generate_vibrational_excitations`. Returns: A tuple containing the hopping operators, the types of commutativities and the diff --git a/qiskit_nature/problems/second_quantization/electronic/builders/aux_fermionic_ops_builder.py b/qiskit_nature/problems/second_quantization/electronic/builders/aux_fermionic_ops_builder.py index 87a705ec26..b3c6879cd1 100644 --- a/qiskit_nature/problems/second_quantization/electronic/builders/aux_fermionic_ops_builder.py +++ b/qiskit_nature/problems/second_quantization/electronic/builders/aux_fermionic_ops_builder.py @@ -15,7 +15,7 @@ from typing import List, Tuple from qiskit_nature.drivers import QMolecule -from qiskit_nature.operators import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from qiskit_nature.problems.second_quantization.electronic.builders.fermionic_op_builder import \ build_ferm_op_from_ints from qiskit_nature.problems.second_quantization.electronic.integrals_calculators import \ diff --git a/qiskit_nature/problems/second_quantization/electronic/builders/fermionic_op_builder.py b/qiskit_nature/problems/second_quantization/electronic/builders/fermionic_op_builder.py index 32162d94b1..831ca466aa 100644 --- a/qiskit_nature/problems/second_quantization/electronic/builders/fermionic_op_builder.py +++ b/qiskit_nature/problems/second_quantization/electronic/builders/fermionic_op_builder.py @@ -17,8 +17,8 @@ import numpy as np -from qiskit_nature.drivers.qmolecule import QMolecule -from qiskit_nature.operators import FermionicOp +from qiskit_nature.drivers import QMolecule +from qiskit_nature.operators.second_quantization import FermionicOp def _build_fermionic_op(q_molecule: QMolecule) -> FermionicOp: diff --git a/qiskit_nature/problems/second_quantization/electronic/builders/hopping_ops_builder.py b/qiskit_nature/problems/second_quantization/electronic/builders/hopping_ops_builder.py index 1730769306..9217dc0119 100644 --- a/qiskit_nature/problems/second_quantization/electronic/builders/hopping_ops_builder.py +++ b/qiskit_nature/problems/second_quantization/electronic/builders/hopping_ops_builder.py @@ -19,10 +19,10 @@ from qiskit.utils import algorithm_globals from qiskit_nature import QiskitNatureError -from qiskit_nature.circuit.library.ansatzes import UCC +from qiskit_nature.circuit.library import UCC from qiskit_nature.drivers import QMolecule from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter def _build_qeom_hopping_ops(q_molecule: QMolecule, qubit_converter: QubitConverter, diff --git a/qiskit_nature/problems/second_quantization/electronic/electronic_structure_problem.py b/qiskit_nature/problems/second_quantization/electronic/electronic_structure_problem.py index 3d9ac9d1b7..fee94c7253 100644 --- a/qiskit_nature/problems/second_quantization/electronic/electronic_structure_problem.py +++ b/qiskit_nature/problems/second_quantization/electronic/electronic_structure_problem.py @@ -20,18 +20,16 @@ from qiskit.opflow import PauliSumOp from qiskit.opflow.primitive_ops import Z2Symmetries +from qiskit_nature.circuit.library.initial_states.hartree_fock import hartree_fock_bitstring from qiskit_nature.drivers import FermionicDriver, QMolecule from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.results import EigenstateResult, ElectronicStructureResult from qiskit_nature.transformers import BaseTransformer -from qiskit_nature.problems.second_quantization.electronic.builders.aux_fermionic_ops_builder \ - import _create_all_aux_operators -from qiskit_nature.problems.second_quantization.electronic.builders.fermionic_op_builder import \ - _build_fermionic_op -from qiskit_nature.problems.second_quantization.electronic.builders.hopping_ops_builder import \ - _build_qeom_hopping_ops -from qiskit_nature.circuit.library.initial_states.hartree_fock import hartree_fock_bitstring + +from .builders.aux_fermionic_ops_builder import _create_all_aux_operators +from .builders.fermionic_op_builder import _build_fermionic_op +from .builders.hopping_ops_builder import _build_qeom_hopping_ops from .result_interpreter import _interpret from ..base_problem import BaseProblem @@ -52,7 +50,7 @@ def __init__(self, driver: FermionicDriver, @property def num_particles(self) -> Tuple[int, int]: molecule_data_transformed = cast(QMolecule, self._molecule_data_transformed) - return (molecule_data_transformed.num_alpha, molecule_data_transformed.num_beta) + return molecule_data_transformed.num_alpha, molecule_data_transformed.num_beta def second_q_ops(self) -> List[SecondQuantizedOp]: """Returns a list of `SecondQuantizedOp` created based on a driver and transformations @@ -88,12 +86,13 @@ def hopping_qeom_ops(self, qubit_converter: QubitConverter, Z2 symmetries stored in this instance are the basis for the commutativity information returned by this method. excitations: the types of excitations to consider. The simple cases for this input are: - - a `str` containing any of the following characters: `s`, `d`, `t` or `q`. - - a single, positive `int` denoting the excitation type (1 == `s`, etc.). - - a list of positive integers. - - and finally a callable which can be used to specify a custom list of excitations. - For more details on how to write such a function refer to the default method, - :meth:`generate_fermionic_excitations`. + + :`str`: containing any of the following characters: `s`, `d`, `t` or `q`. + :`int`: a single, positive integer denoting the excitation type (1 == `s`, etc.). + :`List[int]`: a list of positive integers. + :`Callable`: a function which is used to generate the excitations. + For more details on how to write such a function refer to the default method, + :meth:`generate_fermionic_excitations`. Returns: A tuple containing the hopping operators, the types of commutativities and the @@ -154,16 +153,16 @@ def symmetry_sector_locator(self, z2_symmetries: Z2Symmetries) -> Optional[List[ hf_bitstr = hartree_fock_bitstring( num_spin_orbitals=2 * q_molecule.num_molecular_orbitals, num_particles=self.num_particles) - sector_locator = self._pick_sector(z2_symmetries, hf_bitstr) + sector_locator = ElectronicStructureProblem._pick_sector(z2_symmetries, hf_bitstr) return sector_locator - def _pick_sector(self, z2_symmetries: Z2Symmetries, hf_str: List[bool]) -> Z2Symmetries: + @staticmethod + def _pick_sector(z2_symmetries: Z2Symmetries, hf_str: List[bool]) -> List[int]: # Finding all the symmetries using the find_Z2_symmetries: - taper_coef = [] + taper_coeff: List[int] = [] for sym in z2_symmetries.symmetries: - # pylint: disable=no-member - coef = -1 if np.logical_xor.reduce(np.logical_and(sym.z[::-1], hf_str)) else 1 - taper_coef.append(coef) + coeff = -1 if np.logical_xor.reduce(np.logical_and(sym.z[::-1], hf_str)) else 1 + taper_coeff.append(coeff) - return taper_coef + return taper_coeff diff --git a/qiskit_nature/problems/second_quantization/vibrational/builders/hopping_ops_builder.py b/qiskit_nature/problems/second_quantization/vibrational/builders/hopping_ops_builder.py index ba3ff20467..9321a9120f 100644 --- a/qiskit_nature/problems/second_quantization/vibrational/builders/hopping_ops_builder.py +++ b/qiskit_nature/problems/second_quantization/vibrational/builders/hopping_ops_builder.py @@ -18,9 +18,9 @@ from qiskit.tools import parallel_map from qiskit.utils import algorithm_globals -from qiskit_nature.circuit.library.ansatzes import UVCC -from qiskit_nature.operators import VibrationalOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.circuit.library import UVCC +from qiskit_nature.operators.second_quantization import VibrationalOp +from qiskit_nature.converters.second_quantization import QubitConverter def _build_qeom_hopping_ops(num_modals: List[int], diff --git a/qiskit_nature/problems/second_quantization/vibrational/builders/vibrational_op_builder.py b/qiskit_nature/problems/second_quantization/vibrational/builders/vibrational_op_builder.py index 57ecfddedd..378a1a037d 100644 --- a/qiskit_nature/problems/second_quantization/vibrational/builders/vibrational_op_builder.py +++ b/qiskit_nature/problems/second_quantization/vibrational/builders/vibrational_op_builder.py @@ -17,7 +17,7 @@ from qiskit_nature.drivers import WatsonHamiltonian from qiskit_nature.drivers.bosonic_bases import BosonicBasis, HarmonicBasis -from qiskit_nature.operators.second_quantization.vibrational_op import VibrationalOp +from qiskit_nature.operators.second_quantization import VibrationalOp from qiskit_nature.problems.second_quantization.vibrational.builders.vibrational_label_builder \ import _create_labels diff --git a/qiskit_nature/problems/second_quantization/vibrational/vibrational_structure_problem.py b/qiskit_nature/problems/second_quantization/vibrational/vibrational_structure_problem.py index 72a7fbe410..1d6ad786b8 100644 --- a/qiskit_nature/problems/second_quantization/vibrational/vibrational_structure_problem.py +++ b/qiskit_nature/problems/second_quantization/vibrational/vibrational_structure_problem.py @@ -9,7 +9,7 @@ # 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. -"""The Vibrational Problem class.""" +"""The Vibrational Structure Problem class.""" from functools import partial from typing import cast, Callable, Dict, List, Optional, Tuple, Union @@ -21,21 +21,19 @@ from qiskit_nature.drivers import BosonicDriver, WatsonHamiltonian from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.base_problem import BaseProblem -from qiskit_nature.problems.second_quantization.vibrational.builders.hopping_ops_builder import \ - _build_qeom_hopping_ops -from qiskit_nature.problems.second_quantization.vibrational.builders.vibrational_op_builder import \ - _build_vibrational_op +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.results import EigenstateResult, VibrationalStructureResult from qiskit_nature.transformers import BaseTransformer -from qiskit_nature.problems.second_quantization.vibrational.builders.aux_vibrational_ops_builder \ - import _create_all_aux_operators + +from .builders.hopping_ops_builder import _build_qeom_hopping_ops +from .builders.vibrational_op_builder import _build_vibrational_op +from .builders.aux_vibrational_ops_builder import _create_all_aux_operators from .result_interpreter import _interpret +from ..base_problem import BaseProblem class VibrationalStructureProblem(BaseProblem): - """Vibrational Problem""" + """Vibrational Structure Problem""" def __init__(self, bosonic_driver: BosonicDriver, num_modals: Union[int, List[int]], truncation_order: int, transformers: Optional[List[BaseTransformer]] = None): @@ -91,12 +89,13 @@ def hopping_qeom_ops(self, qubit_converter: QubitConverter, Z2 symmetries stored in this instance are the basis for the commutativity information returned by this method. excitations: the types of excitations to consider. The simple cases for this input are: - - a `str` containing any of the following characters: `s`, `d`, `t` or `q`. - - a single, positive `int` denoting the excitation type (1 == `s`, etc.). - - a list of positive integers. - - and finally a callable which can be used to specify a custom list of excitations. - For more details on how to write such a function refer to the default method, - :meth:`generate_vibrational_excitations`. + + :`str`: containing any of the following characters: `s`, `d`, `t` or `q`. + :`int`: a single, positive integer denoting the excitation type (1 == `s`, etc.). + :`List[int]`: a list of positive integers. + :`Callable`: a function which is used to generate the excitations. + For more details on how to write such a function refer to the default method, + :meth:`generate_vibrational_excitations`. Returns: A tuple containing the hopping operators, the types of commutativities and the diff --git a/qiskit_nature/results/__init__.py b/qiskit_nature/results/__init__.py index fc6ca53170..ec2cacecf3 100644 --- a/qiskit_nature/results/__init__.py +++ b/qiskit_nature/results/__init__.py @@ -11,12 +11,12 @@ # that they have been altered from the originals. """ -Chemistry Results (:mod:`qiskit_nature.results`) -================================================ +Results (:mod:`qiskit_nature.results`) +====================================== .. currentmodule:: qiskit_nature.results -Qiskit's chemistry results for ground and excited states, both Fermionic and Bosonic. Algorithms +Qiskit Nature results such as for electronic and vibrational structure. Algorithms may extend these to provide algorithm specific aspects in their result. Results diff --git a/qiskit_nature/results/electronic_structure_result.py b/qiskit_nature/results/electronic_structure_result.py index 6dfd601719..81ddbbc93b 100644 --- a/qiskit_nature/results/electronic_structure_result.py +++ b/qiskit_nature/results/electronic_structure_result.py @@ -18,7 +18,7 @@ import numpy as np -from qiskit_nature.drivers.qmolecule import QMolecule +from qiskit_nature.drivers import QMolecule from .eigenstate_result import EigenstateResult logger = logging.getLogger(__name__) diff --git a/qiskit_nature/transformers/__init__.py b/qiskit_nature/transformers/__init__.py index b82e3aa165..2e2b1e9617 100644 --- a/qiskit_nature/transformers/__init__.py +++ b/qiskit_nature/transformers/__init__.py @@ -16,10 +16,16 @@ .. currentmodule:: qiskit_nature.transformers +Transformers act on a :class:`~qiskit_nature.drivers.QMolecule` to produce an altered copy of it +as per the specific transformer. So for instance the :class:`FreezeCoreTransformer` will alter the +integrals and number of particles in a way that freezes the core orbitals, storing an extracted +energy in the QMolecule to compensate for this that would need to be included back into any ground +state energy computation to get complete result. .. autosummary:: :toctree: ../stubs/ + BaseTransformer ActiveSpaceTransformer FreezeCoreTransformer diff --git a/qiskit_nature/transformers/active_space_transformer.py b/qiskit_nature/transformers/active_space_transformer.py index 6b801b5cad..790cf2ca89 100644 --- a/qiskit_nature/transformers/active_space_transformer.py +++ b/qiskit_nature/transformers/active_space_transformer.py @@ -17,9 +17,10 @@ import logging import numpy as np +from qiskit_nature import QiskitNatureError +from qiskit_nature.drivers import QMolecule + from .base_transformer import BaseTransformer -from .. import QiskitNatureError -from ..drivers import QMolecule logger = logging.getLogger(__name__) diff --git a/qiskit_nature/transformers/freeze_core_transformer.py b/qiskit_nature/transformers/freeze_core_transformer.py index 9a56f2148a..0c49d830f4 100644 --- a/qiskit_nature/transformers/freeze_core_transformer.py +++ b/qiskit_nature/transformers/freeze_core_transformer.py @@ -15,8 +15,9 @@ from typing import List, Optional import logging +from qiskit_nature.drivers import QMolecule + from .active_space_transformer import ActiveSpaceTransformer -from ..drivers import QMolecule logger = logging.getLogger(__name__) @@ -31,7 +32,7 @@ def __init__(self, freeze_core: bool = True, orbitals. The orbitals to be removed are specified in two ways: - 1. When `freeeze_core` is enabled (the default), the `core_orbitals` listed in the + 1. When `freeze_core` is enabled (the default), the `core_orbitals` listed in the `QMolecule` are made inactive and removed in the same fashion as in the :class:`ActiveSpaceTransformer`. 2. Additionally, unoccupied molecular orbitals can be removed via a list of indices diff --git a/test/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py b/test/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py index bbf9c91987..a8b97b7608 100644 --- a/test/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py +++ b/test/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py @@ -10,7 +10,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -""" Test NumericalqEOM excited states calculation """ +""" Test Numerical qEOM excited states calculation """ import unittest @@ -20,22 +20,18 @@ from qiskit.utils import algorithm_globals, QuantumInstance from qiskit.algorithms.optimizers import COBYLA -from qiskit_nature.drivers import BaseDriver, WatsonHamiltonian +from qiskit_nature.drivers import BosonicDriver, WatsonHamiltonian from qiskit_nature.mappers.second_quantization import DirectMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.vibrational.vibrational_structure_problem import \ - VibrationalStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization.vibrational import VibrationalStructureProblem -from qiskit_nature.algorithms.ground_state_solvers import ( +from qiskit_nature.algorithms import ( GroundStateEigensolver, NumPyMinimumEigensolverFactory, - VQEUVCCFactory -) -from qiskit_nature.algorithms.excited_states_solvers import ( - QEOM, ExcitedStatesEigensolver, NumPyEigensolverFactory + VQEUVCCFactory, QEOM, ExcitedStatesEigensolver, NumPyEigensolverFactory ) -class _DummyBosonicDriver(BaseDriver): +class _DummyBosonicDriver(BosonicDriver): def __init__(self): super().__init__() diff --git a/test/algorithms/excited_state_solvers/test_excited_states_solvers.py b/test/algorithms/excited_state_solvers/test_excited_states_solvers.py index 4648d4796c..6b7aab6117 100644 --- a/test/algorithms/excited_state_solvers/test_excited_states_solvers.py +++ b/test/algorithms/excited_state_solvers/test_excited_states_solvers.py @@ -10,7 +10,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -""" Test NumericalqEOM excited states calculation """ +""" Test Numerical qEOM excited states calculation """ import unittest from test import QiskitNatureTestCase @@ -22,17 +22,16 @@ from qiskit_nature import QiskitNatureError from qiskit_nature.drivers import PySCFDriver, UnitsType from qiskit_nature.mappers.second_quantization import JordanWignerMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.problems.second_quantization import ElectronicStructureProblem -from qiskit_nature.algorithms.ground_state_solvers import (GroundStateEigensolver, - VQEUCCFactory, ) -from qiskit_nature.algorithms.excited_states_solvers import ( - NumPyEigensolverFactory, ExcitedStatesEigensolver, QEOM, +from qiskit_nature.algorithms import ( + GroundStateEigensolver, VQEUCCFactory, + NumPyEigensolverFactory, ExcitedStatesEigensolver, QEOM ) class TestNumericalQEOMESCCalculation(QiskitNatureTestCase): - """ Test NumericalqEOM excited states calculation """ + """ Test Numerical qEOM excited states calculation """ def setUp(self): super().setUp() diff --git a/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_ucc_factory.py b/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_ucc_factory.py index 7da7820156..e8efca4b94 100644 --- a/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_ucc_factory.py +++ b/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_ucc_factory.py @@ -10,7 +10,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -""" Test VQE UCC MinimumEigensovler Factory """ +""" Test VQE UCC MinimumEigensolver Factory """ import unittest @@ -21,14 +21,13 @@ from qiskit.opflow import AerPauliExpectation from qiskit.algorithms.optimizers import COBYLA from qiskit_nature.circuit.library import HartreeFock, UCCSD -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.mappers.second_quantization import JordanWignerMapper -from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import \ - VQEUCCFactory +from qiskit_nature.algorithms import VQEUCCFactory class TestVQEUCCFactory(QiskitNatureTestCase): - """ Test VQE UCC MinimumEigensovler Factory """ + """ Test VQE UCC MinimumEigensolver Factory """ # NOTE: The actual usage of this class is mostly tested in combination with the ground-state # eigensolvers (one module above). diff --git a/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_uvcc_factory.py b/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_uvcc_factory.py index 50838b7c18..62dc477735 100644 --- a/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_uvcc_factory.py +++ b/test/algorithms/ground_state_solvers/minimum_eigensolver_factories/test_vqe_uvcc_factory.py @@ -9,7 +9,7 @@ # 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. -""" Test VQE UVCC MinimumEigensovler Factory """ +""" Test VQE UVCC MinimumEigensolver Factory """ import unittest @@ -18,16 +18,14 @@ from qiskit.utils import QuantumInstance from qiskit.opflow import AerPauliExpectation from qiskit.algorithms.optimizers import COBYLA -from qiskit_nature.circuit.library.ansatzes import UVCCSD -from qiskit_nature.circuit.library import HartreeFock -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.circuit.library import HartreeFock, UVCCSD +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.mappers.second_quantization import JordanWignerMapper -from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import \ - VQEUVCCFactory +from qiskit_nature.algorithms import VQEUVCCFactory class TestVQEUVCCFactory(QiskitNatureTestCase): - """ Test VQE UVCC MinimumEigensovler Factory """ + """ Test VQE UVCC MinimumEigensolver Factory """ # NOTE: The actual usage of this class is mostly tested in combination with the ground-state # eigensolvers (one module above). diff --git a/test/algorithms/ground_state_solvers/test_adapt_vqe.py b/test/algorithms/ground_state_solvers/test_adapt_vqe.py index 1fe357787f..4da63256ec 100644 --- a/test/algorithms/ground_state_solvers/test_adapt_vqe.py +++ b/test/algorithms/ground_state_solvers/test_adapt_vqe.py @@ -25,12 +25,12 @@ from qiskit.algorithms import VQE from qiskit.algorithms.optimizers import L_BFGS_B from qiskit_nature import QiskitNatureError -from qiskit_nature.algorithms.ground_state_solvers import AdaptVQE, VQEUCCFactory +from qiskit_nature.algorithms import AdaptVQE, VQEUCCFactory from qiskit_nature.circuit.library import HartreeFock, UCC from qiskit_nature.drivers import PySCFDriver, UnitsType, QMolecule from qiskit_nature.mappers.second_quantization import ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem from qiskit_nature.problems.second_quantization.electronic.builders.fermionic_op_builder import \ build_ferm_op_from_ints diff --git a/test/algorithms/ground_state_solvers/test_advanced_ucc_variants.py b/test/algorithms/ground_state_solvers/test_advanced_ucc_variants.py index 2622f8d619..894c862570 100644 --- a/test/algorithms/ground_state_solvers/test_advanced_ucc_variants.py +++ b/test/algorithms/ground_state_solvers/test_advanced_ucc_variants.py @@ -22,13 +22,12 @@ from qiskit.algorithms.optimizers import SLSQP from qiskit.test import slow_test -from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver -from qiskit_nature.circuit.library import HartreeFock -from qiskit_nature.circuit.library.ansatzes import SUCCD, PUCCD +from qiskit_nature.algorithms import GroundStateEigensolver +from qiskit_nature.circuit.library import HartreeFock, SUCCD, PUCCD from qiskit_nature.drivers import PySCFDriver from qiskit_nature.mappers.second_quantization import ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem from qiskit_nature.transformers import FreezeCoreTransformer diff --git a/test/algorithms/ground_state_solvers/test_groundstate_eigensolver.py b/test/algorithms/ground_state_solvers/test_groundstate_eigensolver.py index ce3bf319c0..9718b69f99 100644 --- a/test/algorithms/ground_state_solvers/test_groundstate_eigensolver.py +++ b/test/algorithms/ground_state_solvers/test_groundstate_eigensolver.py @@ -26,16 +26,13 @@ from qiskit.test import slow_test from qiskit.utils import QuantumInstance, algorithm_globals -from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver -from qiskit_nature.algorithms.ground_state_solvers.minimum_eigensolver_factories import \ - (VQEUCCFactory, NumPyMinimumEigensolverFactory, ) -from qiskit_nature.circuit.library.ansatzes import UCC, UCCSD -from qiskit_nature.circuit.library.initial_states import HartreeFock +from qiskit_nature.algorithms import ( + GroundStateEigensolver, VQEUCCFactory, NumPyMinimumEigensolverFactory) +from qiskit_nature.circuit.library import HartreeFock, UCC, UCCSD from qiskit_nature.drivers import HDF5Driver from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic.electronic_structure_problem import \ - ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem from qiskit_nature.problems.second_quantization.electronic.builders.fermionic_op_builder import \ build_ferm_op_from_ints diff --git a/test/algorithms/ground_state_solvers/test_swaprz.py b/test/algorithms/ground_state_solvers/test_swaprz.py index 5a37cfc9c0..b6e7991504 100644 --- a/test/algorithms/ground_state_solvers/test_swaprz.py +++ b/test/algorithms/ground_state_solvers/test_swaprz.py @@ -21,12 +21,12 @@ from qiskit.circuit.library import ExcitationPreserving from qiskit.test import slow_test from qiskit.utils import QuantumInstance, algorithm_globals -from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver +from qiskit_nature.algorithms import GroundStateEigensolver from qiskit_nature.circuit.library import HartreeFock from qiskit_nature.drivers import HDF5Driver from qiskit_nature.mappers.second_quantization import ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem @slow_test diff --git a/test/algorithms/pes_samplers/test_bopes_sampler.py b/test/algorithms/pes_samplers/test_bopes_sampler.py index a3638429d2..85101f9ceb 100644 --- a/test/algorithms/pes_samplers/test_bopes_sampler.py +++ b/test/algorithms/pes_samplers/test_bopes_sampler.py @@ -20,13 +20,12 @@ from qiskit.algorithms import NumPyMinimumEigensolver from qiskit.utils import algorithm_globals -from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver -from qiskit_nature.algorithms.pes_samplers.bopes_sampler import BOPESSampler -from qiskit_nature.algorithms.pes_samplers.potentials.morse_potential import MorsePotential +from qiskit_nature.algorithms import GroundStateEigensolver, BOPESSampler +from qiskit_nature.algorithms.pes_samplers import MorsePotential from qiskit_nature.drivers import Molecule, PySCFDriver from qiskit_nature.mappers.second_quantization import ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem class TestBOPES(unittest.TestCase): diff --git a/test/algorithms/pes_samplers/test_extrapolators.py b/test/algorithms/pes_samplers/test_extrapolators.py index 9fdc2f6b77..48e2168101 100644 --- a/test/algorithms/pes_samplers/test_extrapolators.py +++ b/test/algorithms/pes_samplers/test_extrapolators.py @@ -18,9 +18,9 @@ import unittest from sklearn import linear_model from qiskit_nature.exceptions import QiskitNatureError -from qiskit_nature.algorithms.pes_samplers.extrapolator import Extrapolator, \ - WindowExtrapolator, PolynomialExtrapolator, DifferentialExtrapolator, \ - PCAExtrapolator, SieveExtrapolator +from qiskit_nature.algorithms.pes_samplers import ( + Extrapolator, WindowExtrapolator, PolynomialExtrapolator, DifferentialExtrapolator, + PCAExtrapolator, SieveExtrapolator) PARAM_DICT = { diff --git a/test/circuit/library/ansatzes/test_chc.py b/test/circuit/library/ansatzes/test_chc.py index 9a8519d40d..ae444d8333 100644 --- a/test/circuit/library/ansatzes/test_chc.py +++ b/test/circuit/library/ansatzes/test_chc.py @@ -20,19 +20,18 @@ from qiskit.utils import QuantumInstance, algorithm_globals from qiskit.algorithms import VQE from qiskit.algorithms.optimizers import COBYLA -from qiskit_nature.circuit.library.ansatzes import CHC -from qiskit_nature.circuit.library.initial_states import VSCF +from qiskit_nature.circuit.library import CHC, VSCF from qiskit_nature.circuit.library.ansatzes.utils.vibration_excitation_generator import \ generate_vibration_excitations -from qiskit_nature.mappers.second_quantization.direct_mapper import DirectMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.operators.second_quantization.vibrational_op import VibrationalOp +from qiskit_nature.mappers.second_quantization import DirectMapper +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.operators.second_quantization import VibrationalOp from qiskit_nature.problems.second_quantization.vibrational.builders.vibrational_label_builder \ import _create_labels class TestCHCVSCF(QiskitNatureTestCase): - """Test for these extensions.""" + """Test for CHC and VSCF library circuits. """ def setUp(self): super().setUp() diff --git a/test/circuit/library/ansatzes/test_evolved_op_ansatz.py b/test/circuit/library/ansatzes/test_evolved_op_ansatz.py index de7157c6c7..fc39f5160a 100644 --- a/test/circuit/library/ansatzes/test_evolved_op_ansatz.py +++ b/test/circuit/library/ansatzes/test_evolved_op_ansatz.py @@ -17,7 +17,7 @@ from qiskit.circuit import QuantumCircuit from qiskit.opflow import X, Y, Z, I, MatrixEvolution -from qiskit_nature.circuit.library.ansatzes import EvolvedOperatorAnsatz +from qiskit_nature.circuit.library import EvolvedOperatorAnsatz class TestEvolvedOperatorAnsatz(QiskitNatureTestCase): diff --git a/test/circuit/library/ansatzes/test_puccd.py b/test/circuit/library/ansatzes/test_puccd.py index f5a6cde5a8..061f257ea3 100644 --- a/test/circuit/library/ansatzes/test_puccd.py +++ b/test/circuit/library/ansatzes/test_puccd.py @@ -10,7 +10,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -"""Test the PUCC Ansatz.""" +"""Test the PUCCD Ansatz.""" from test import QiskitNatureTestCase from test.circuit.library.ansatzes.test_ucc import assert_ucc_like_ansatz @@ -18,10 +18,10 @@ from ddt import ddt, data, unpack from qiskit_nature import QiskitNatureError -from qiskit_nature.circuit.library.ansatzes import PUCCD +from qiskit_nature.circuit.library import PUCCD from qiskit_nature.mappers.second_quantization import JordanWignerMapper from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter @ddt diff --git a/test/circuit/library/ansatzes/test_succd.py b/test/circuit/library/ansatzes/test_succd.py index 0eb1dcabf6..57a3aad6da 100644 --- a/test/circuit/library/ansatzes/test_succd.py +++ b/test/circuit/library/ansatzes/test_succd.py @@ -18,10 +18,10 @@ from ddt import ddt, data, unpack from qiskit_nature import QiskitNatureError -from qiskit_nature.circuit.library.ansatzes import SUCCD +from qiskit_nature.circuit.library import SUCCD from qiskit_nature.mappers.second_quantization import JordanWignerMapper from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter @ddt diff --git a/test/circuit/library/ansatzes/test_ucc.py b/test/circuit/library/ansatzes/test_ucc.py index e6ee5e04ad..2e8ff889b0 100644 --- a/test/circuit/library/ansatzes/test_ucc.py +++ b/test/circuit/library/ansatzes/test_ucc.py @@ -16,10 +16,10 @@ from ddt import ddt, data, unpack -from qiskit_nature.circuit.library.ansatzes import UCC +from qiskit_nature.circuit.library import UCC from qiskit_nature.mappers.second_quantization import JordanWignerMapper from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter def assert_ucc_like_ansatz(test_case, ansatz, num_spin_orbitals, expected_ops): diff --git a/test/circuit/library/ansatzes/test_uccsd.py b/test/circuit/library/ansatzes/test_uccsd.py index 65f1141bd1..2b9a1cdd04 100644 --- a/test/circuit/library/ansatzes/test_uccsd.py +++ b/test/circuit/library/ansatzes/test_uccsd.py @@ -17,10 +17,10 @@ from ddt import ddt, data, unpack -from qiskit_nature.circuit.library.ansatzes import UCCSD +from qiskit_nature.circuit.library import UCCSD from qiskit_nature.mappers.second_quantization import JordanWignerMapper from qiskit_nature.operators.second_quantization import FermionicOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter @ddt diff --git a/test/circuit/library/ansatzes/test_uvcc.py b/test/circuit/library/ansatzes/test_uvcc.py index 4d6064d727..ea87c2d0c2 100644 --- a/test/circuit/library/ansatzes/test_uvcc.py +++ b/test/circuit/library/ansatzes/test_uvcc.py @@ -22,11 +22,10 @@ from qiskit.utils import QuantumInstance, algorithm_globals from qiskit.algorithms import VQE from qiskit.algorithms.optimizers import COBYLA -from qiskit_nature.circuit.library.ansatzes import UVCC -from qiskit_nature.circuit.library.initial_states import VSCF +from qiskit_nature.circuit.library import UVCC, VSCF from qiskit_nature.mappers.second_quantization import DirectMapper from qiskit_nature.operators.second_quantization import VibrationalOp -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.problems.second_quantization.vibrational.builders.vibrational_label_builder \ import _create_labels diff --git a/test/circuit/library/initial_states/test_hartree_fock.py b/test/circuit/library/initial_states/test_hartree_fock.py index 50e749669c..9ebb73d823 100644 --- a/test/circuit/library/initial_states/test_hartree_fock.py +++ b/test/circuit/library/initial_states/test_hartree_fock.py @@ -21,9 +21,9 @@ from qiskit.quantum_info.operators.symplectic import Pauli from qiskit_nature.circuit.library import HartreeFock from qiskit_nature.circuit.library.initial_states.hartree_fock import hartree_fock_bitstring -from qiskit_nature.mappers.second_quantization import (BravyiKitaevMapper, JordanWignerMapper, - ParityMapper) -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.mappers.second_quantization import ( + BravyiKitaevMapper, JordanWignerMapper, ParityMapper) +from qiskit_nature.converters.second_quantization import QubitConverter class TestHartreeFock(QiskitNatureTestCase): diff --git a/test/drivers/pyscfd/test_driver_methods_pyscf.py b/test/drivers/pyscfd/test_driver_methods_pyscf.py index 295ad46dd6..b9d688e918 100644 --- a/test/drivers/pyscfd/test_driver_methods_pyscf.py +++ b/test/drivers/pyscfd/test_driver_methods_pyscf.py @@ -18,7 +18,7 @@ from qiskit_nature.drivers import PySCFDriver, UnitsType, HFMethodType from qiskit_nature import QiskitNatureError from qiskit_nature.mappers.second_quantization import BravyiKitaevMapper, ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization.qubit_converter import QubitConverter from qiskit_nature.transformers import FreezeCoreTransformer diff --git a/test/drivers/test_driver_methods_gsc.py b/test/drivers/test_driver_methods_gsc.py index 65d618655c..ffde5c7479 100644 --- a/test/drivers/test_driver_methods_gsc.py +++ b/test/drivers/test_driver_methods_gsc.py @@ -18,12 +18,12 @@ from test import QiskitNatureTestCase from qiskit.algorithms import NumPyMinimumEigensolver -from qiskit_nature.algorithms.ground_state_solvers import GroundStateEigensolver +from qiskit_nature.algorithms import GroundStateEigensolver from qiskit_nature.drivers import FermionicDriver from qiskit_nature.mappers.second_quantization import JordanWignerMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem -from qiskit_nature.transformers.base_transformer import BaseTransformer +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem +from qiskit_nature.transformers import BaseTransformer class TestDriverMethods(QiskitNatureTestCase): diff --git a/test/mappers/second_quantization/test_linear_mapper.py b/test/mappers/second_quantization/test_linear_mapper.py index 9f33da3b06..0224ead2ee 100644 --- a/test/mappers/second_quantization/test_linear_mapper.py +++ b/test/mappers/second_quantization/test_linear_mapper.py @@ -19,7 +19,7 @@ from ddt import ddt, data, unpack from qiskit.opflow import X, Y, Z, I -from qiskit_nature.operators import SpinOp +from qiskit_nature.operators.second_quantization import SpinOp from qiskit_nature.mappers.second_quantization import LinearMapper diff --git a/test/operators/second_quantization/test_fermionic_op.py b/test/operators/second_quantization/test_fermionic_op.py index 78f77468a5..27be2db63f 100644 --- a/test/operators/second_quantization/test_fermionic_op.py +++ b/test/operators/second_quantization/test_fermionic_op.py @@ -19,7 +19,7 @@ from ddt import data, ddt, unpack -from qiskit_nature.operators import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from .utils import str2list, str2str, str2tuple diff --git a/test/operators/second_quantization/test_qubit_converter.py b/test/operators/second_quantization/test_qubit_converter.py index 06733c4b7b..fce9498e8d 100644 --- a/test/operators/second_quantization/test_qubit_converter.py +++ b/test/operators/second_quantization/test_qubit_converter.py @@ -22,8 +22,8 @@ from qiskit_nature import QiskitNatureError from qiskit_nature.drivers import HDF5Driver from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter -from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem +from qiskit_nature.converters.second_quantization import QubitConverter +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem from qiskit_nature.problems.second_quantization.electronic.builders import fermionic_op_builder diff --git a/test/operators/second_quantization/test_spin_op.py b/test/operators/second_quantization/test_spin_op.py index 8182fd2f00..9b744964ec 100644 --- a/test/operators/second_quantization/test_spin_op.py +++ b/test/operators/second_quantization/test_spin_op.py @@ -17,13 +17,12 @@ from functools import lru_cache from itertools import product from test import QiskitNatureTestCase -from typing import Callable, Optional import numpy as np from ddt import data, ddt, unpack from qiskit.quantum_info import Pauli -from qiskit_nature.operators import SpinOp +from qiskit_nature.operators.second_quantization import SpinOp from .utils import str2list, str2str, str2tuple diff --git a/test/operators/second_quantization/test_vibrational_op.py b/test/operators/second_quantization/test_vibrational_op.py index 157c8cda73..4d6a1f3c94 100644 --- a/test/operators/second_quantization/test_vibrational_op.py +++ b/test/operators/second_quantization/test_vibrational_op.py @@ -16,7 +16,7 @@ import numpy as np from ddt import data, ddt -from qiskit_nature.operators.second_quantization.vibrational_op import VibrationalOp +from qiskit_nature.operators.second_quantization import VibrationalOp @ddt diff --git a/test/operators/second_quantization/utils.py b/test/operators/second_quantization/utils.py index a141943e9d..19584121a5 100644 --- a/test/operators/second_quantization/utils.py +++ b/test/operators/second_quantization/utils.py @@ -21,7 +21,7 @@ def str2str(string: str): def str2tuple(string: str): """Construct the tuple data from string for SecondQuantizedOp.""" - return (string, 1) + return string, 1 def str2list(string: str): diff --git a/test/problems/second_quantization/electronic/builders/test_fermionic_op_builder.py b/test/problems/second_quantization/electronic/builders/test_fermionic_op_builder.py index a927ae2921..982c72a6c7 100644 --- a/test/problems/second_quantization/electronic/builders/test_fermionic_op_builder.py +++ b/test/problems/second_quantization/electronic/builders/test_fermionic_op_builder.py @@ -15,7 +15,7 @@ from test.problems.second_quantization.electronic.resources.resource_reader import \ read_expected_file import numpy as np -from qiskit_nature.operators import FermionicOp +from qiskit_nature.operators.second_quantization import FermionicOp from qiskit_nature.problems.second_quantization.electronic.builders import fermionic_op_builder from qiskit_nature.drivers import HDF5Driver diff --git a/test/problems/second_quantization/electronic/builders/test_hopping_ops_builder.py b/test/problems/second_quantization/electronic/builders/test_hopping_ops_builder.py index e06782a61c..8c7fb8f042 100644 --- a/test/problems/second_quantization/electronic/builders/test_hopping_ops_builder.py +++ b/test/problems/second_quantization/electronic/builders/test_hopping_ops_builder.py @@ -19,7 +19,7 @@ from qiskit_nature import QiskitNatureError from qiskit_nature.drivers import PySCFDriver, UnitsType from qiskit_nature.mappers.second_quantization import JordanWignerMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.problems.second_quantization import ElectronicStructureProblem from qiskit_nature.problems.second_quantization.electronic.builders.hopping_ops_builder import \ _build_qeom_hopping_ops diff --git a/test/problems/second_quantization/electronic/test_electronic_structure_problem.py b/test/problems/second_quantization/electronic/test_electronic_structure_problem.py index 05bde9c3c0..7cfc34f903 100644 --- a/test/problems/second_quantization/electronic/test_electronic_structure_problem.py +++ b/test/problems/second_quantization/electronic/test_electronic_structure_problem.py @@ -19,8 +19,7 @@ from qiskit_nature.transformers import ActiveSpaceTransformer from qiskit_nature.drivers import HDF5Driver from qiskit_nature.operators.second_quantization import SecondQuantizedOp -from qiskit_nature.problems.second_quantization.electronic.electronic_structure_problem import \ - ElectronicStructureProblem +from qiskit_nature.problems.second_quantization import ElectronicStructureProblem class TestElectronicStructureProblem(QiskitNatureTestCase): diff --git a/test/problems/second_quantization/vibrational/builders/test_hopping_ops_builder.py b/test/problems/second_quantization/vibrational/builders/test_hopping_ops_builder.py index 13e0c16509..d6d7249a95 100644 --- a/test/problems/second_quantization/vibrational/builders/test_hopping_ops_builder.py +++ b/test/problems/second_quantization/vibrational/builders/test_hopping_ops_builder.py @@ -18,7 +18,7 @@ from qiskit.utils import algorithm_globals from qiskit_nature.mappers.second_quantization import DirectMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.problems.second_quantization import VibrationalStructureProblem from qiskit_nature.problems.second_quantization.vibrational.builders.hopping_ops_builder import \ _build_qeom_hopping_ops diff --git a/test/problems/second_quantization/vibrational/test_vibrational_problem.py b/test/problems/second_quantization/vibrational/test_vibrational_problem.py index a1523f22e0..a504d4281d 100644 --- a/test/problems/second_quantization/vibrational/test_vibrational_problem.py +++ b/test/problems/second_quantization/vibrational/test_vibrational_problem.py @@ -12,9 +12,8 @@ """Tests Vibrational Problem.""" from test import QiskitNatureTestCase -from qiskit_nature.operators.second_quantization.vibrational_op import VibrationalOp -from qiskit_nature.problems.second_quantization.vibrational.vibrational_structure_problem import \ - VibrationalStructureProblem +from qiskit_nature.operators.second_quantization import VibrationalOp +from qiskit_nature.problems.second_quantization import VibrationalStructureProblem from qiskit_nature.drivers import GaussianForcesDriver diff --git a/test/test_end2end_with_vqe.py b/test/test_end2end_with_vqe.py index a0ddd579f7..745260bfa6 100644 --- a/test/test_end2end_with_vqe.py +++ b/test/test_end2end_with_vqe.py @@ -23,7 +23,7 @@ from qiskit.utils import algorithm_globals, QuantumInstance from qiskit_nature.drivers import HDF5Driver from qiskit_nature.mappers.second_quantization import ParityMapper -from qiskit_nature.operators.second_quantization.qubit_converter import QubitConverter +from qiskit_nature.converters.second_quantization.qubit_converter import QubitConverter from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem diff --git a/test/test_readme_sample.py b/test/test_readme_sample.py index 02750b5641..3f6bdfed46 100644 --- a/test/test_readme_sample.py +++ b/test/test_readme_sample.py @@ -80,7 +80,7 @@ def print(*args): # 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)