Skip to content

Commit

Permalink
Merge branch 'main' into slater-gates
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques authored Dec 17, 2021
2 parents 412e673 + d39ce24 commit d49ed8b
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 37 deletions.
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
warn_unused_configs = True
ignore_missing_imports = True
strict_optional = False
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True

### Output
show_error_codes = True
Expand Down
2 changes: 1 addition & 1 deletion qiskit_nature/algorithms/excited_states_solvers/qeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _build_one_sector(available_hopping_ops, untapered_op, z2_symmetries):
all_matrix_operators[f"v_{m_u}_{n_u}"] = v_mat_op

try:
z2_symmetries = self._gsc.qubit_converter.z2symmetries # type: ignore
z2_symmetries = self._gsc.qubit_converter.z2symmetries
except AttributeError:
z2_symmetries = Z2Symmetries([], [], [])

Expand Down
2 changes: 1 addition & 1 deletion qiskit_nature/algorithms/pes_samplers/bopes_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _run_single_point(self, point: float) -> EigenstateResult:
# Save optimal point to bootstrap
if isinstance(self._gss.solver, VariationalAlgorithm): # type: ignore
# at every point evaluation, the optimal params are updated
optimal_params = result.raw_result.optimal_point # type: ignore
optimal_params = result.raw_result.optimal_point
self._points_optparams[point] = optimal_params

return result
4 changes: 2 additions & 2 deletions qiskit_nature/drivers/bosonic_bases/harmonic_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

""" Bosonic Harmonic Basis """

from typing import Dict, List, Tuple, cast
from typing import Dict, List, Tuple

import numpy as np

Expand Down Expand Up @@ -164,7 +164,7 @@ class to be mapped to a qubit hamiltonian.
}

for entry in self._watson.data: # Entry is coeff (float) followed by indices (ints)
coeff0 = cast(float, entry[0])
coeff0 = entry[0]
indices = np.asarray(entry[1:], dtype=int)

kinetic_term = False
Expand Down
2 changes: 1 addition & 1 deletion qiskit_nature/drivers/pyscfd/pyscfdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _check_valid():
MissingOptionalLibraryError: If PySCF is not installed.
"""
try:
spec = importlib.util.find_spec("pyscf") # type: ignore
spec = importlib.util.find_spec("pyscf")
if spec is not None:
return
except Exception as ex: # pylint: disable=broad-except
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def driver_class_from_type(
raise MissingOptionalLibraryError(
libname=driver_type, name="ElectronicStructureDriverType"
)
driver_class.check_installed() # type: ignore
driver_class.check_method_supported(method) # type: ignore
driver_class.check_installed()
driver_class.check_method_supported(method)

logger.debug("%s found from type %s.", driver_class.__name__, driver_type.value)
return driver_class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(
validate_min("max_cycle", max_cycle, 1)

# we use the property-setter to deal with conversion
self.atom = atom # type: ignore
self.atom = atom
self._unit = unit
self._charge = charge
self._spin = spin
Expand Down Expand Up @@ -337,10 +337,7 @@ def from_molecule(
if key not in ["self"] and key in args:
kwargs[key] = value

kwargs["atom"] = [ # type: ignore
" ".join(map(str, (name, *coord))) # type: ignore
for (name, coord) in molecule.geometry
]
kwargs["atom"] = [" ".join(map(str, (name, *coord))) for (name, coord) in molecule.geometry]
kwargs["charge"] = molecule.charge
kwargs["spin"] = molecule.multiplicity - 1
kwargs["unit"] = molecule.units
Expand All @@ -367,7 +364,7 @@ def check_installed() -> None:
MissingOptionalLibraryError: If PySCF is not installed.
"""
try:
spec = importlib.util.find_spec("pyscf") # type: ignore
spec = importlib.util.find_spec("pyscf")
if spec is not None:
return
except Exception as ex: # pylint: disable=broad-except
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def driver_class_from_type(
raise MissingOptionalLibraryError(
libname=driver_type, name="VibrationalStructureDriverType"
)
driver_class.check_installed() # type: ignore
driver_class.check_installed()

logger.debug("%s found from type %s.", driver_class.__name__, driver_type.value)
return driver_class
Expand Down
6 changes: 3 additions & 3 deletions qiskit_nature/operators/second_quantization/fermionic_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def __init__(
self._data = [
(
self._substituted_label([(c, int(i)) for i, c in enumerate(label)]),
complex(coeff), # type: ignore
complex(coeff),
)
for label, coeff in data
]
Expand All @@ -298,7 +298,7 @@ def __init__(
self._substituted_label(
[(c[0], int(c[2:])) for c in label.split()] # type: ignore
),
complex(coeff), # type: ignore
complex(coeff),
)
for label, coeff in data
]
Expand Down Expand Up @@ -436,7 +436,7 @@ def add(self, other: "FermionicOp") -> "FermionicOp":
def to_list(
self,
display_format: Optional[str] = None,
) -> List[Tuple[str, complex]]: # type: ignore
) -> List[Tuple[str, complex]]:
"""Returns the operators internal contents in list-format.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def _build_qeom_hopping_ops(
if isinstance(excitations, (str, int)) or (
isinstance(excitations, list) and all(isinstance(exc, int) for exc in excitations)
):
excitations = cast(Union[str, int, List[int]], excitations)
ansatz = UCC(qubit_converter, (num_alpha, num_beta), num_spin_orbitals, excitations)
excitations_list = ansatz._get_excitation_list()
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def _build_qeom_hopping_ops(
if isinstance(excitations, (str, int)) or (
isinstance(excitations, list) and all(isinstance(exc, int) for exc in excitations)
):
excitations = cast(Union[str, int, List[int]], excitations)
ansatz = UVCC(qubit_converter, num_modals, excitations)
excitations_list = ansatz._get_excitation_list()
else:
Expand Down Expand Up @@ -90,7 +89,7 @@ def _build_qeom_hopping_ops(
# at the moment we do not have any type of commutativity in the bosonic case.
type_of_commutativities: Dict[str, List[bool]] = {}

return hopping_operators, type_of_commutativities, excitation_indices # type: ignore
return hopping_operators, type_of_commutativities, excitation_indices


def _build_single_hopping_operator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ def interpret(self, result: EigenstateResult) -> None:
if not isinstance(result.aux_operator_eigenvalues, list):
aux_operator_eigenvalues = [result.aux_operator_eigenvalues]
else:
aux_operator_eigenvalues = result.aux_operator_eigenvalues # type: ignore[assignment]
aux_operator_eigenvalues = result.aux_operator_eigenvalues
for aux_op_eigenvalues in aux_operator_eigenvalues:
if aux_op_eigenvalues is None:
continue

_key = self.name if isinstance(aux_op_eigenvalues, dict) else 1

if aux_op_eigenvalues[_key] is not None:
total_angular_momentum = aux_op_eigenvalues[_key][0].real # type: ignore
total_angular_momentum = aux_op_eigenvalues[_key][0].real
result.total_angular_momentum.append(total_angular_momentum)

if expected is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def interpret(self, result: EigenstateResult) -> None:
if not isinstance(result.aux_operator_eigenvalues, list):
aux_operator_eigenvalues = [result.aux_operator_eigenvalues]
else:
aux_operator_eigenvalues = result.aux_operator_eigenvalues # type: ignore[assignment]
aux_operator_eigenvalues = result.aux_operator_eigenvalues

for aux_op_eigenvalues in aux_operator_eigenvalues:
if aux_op_eigenvalues is None:
Expand All @@ -250,9 +250,9 @@ def interpret(self, result: EigenstateResult) -> None:
for prop in iter(self):
moment: Optional[Tuple[complex, complex]]
try:
moment = aux_op_eigenvalues[axes_order[prop._axis] + 3] # type: ignore
moment = aux_op_eigenvalues[axes_order[prop._axis] + 3]
except KeyError:
moment = aux_op_eigenvalues.get(prop.name, None) # type: ignore
moment = aux_op_eigenvalues.get(prop.name, None)
if moment is not None:
dipole_moment[axes_order[prop._axis]] = moment[0].real # type: ignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def interpret(self, result: EigenstateResult) -> None:
if not isinstance(result.aux_operator_eigenvalues, list):
aux_operator_eigenvalues = [result.aux_operator_eigenvalues]
else:
aux_operator_eigenvalues = result.aux_operator_eigenvalues # type: ignore[assignment]
aux_operator_eigenvalues = result.aux_operator_eigenvalues
for aux_op_eigenvalues in aux_operator_eigenvalues:
if aux_op_eigenvalues is None:
continue

_key = self.name if isinstance(aux_op_eigenvalues, dict) else 2

if aux_op_eigenvalues[_key] is not None:
result.magnetization.append(aux_op_eigenvalues[_key][0].real) # type: ignore
result.magnetization.append(aux_op_eigenvalues[_key][0].real)
else:
result.magnetization.append(None)
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ def interpret(self, result: EigenstateResult) -> None:
if not isinstance(result.aux_operator_eigenvalues, list):
aux_operator_eigenvalues = [result.aux_operator_eigenvalues]
else:
aux_operator_eigenvalues = result.aux_operator_eigenvalues # type: ignore[assignment]
aux_operator_eigenvalues = result.aux_operator_eigenvalues
for aux_op_eigenvalues in aux_operator_eigenvalues:
if aux_op_eigenvalues is None:
continue

_key = self.name if isinstance(aux_op_eigenvalues, dict) else 0

if aux_op_eigenvalues[_key] is not None:
n_particles = aux_op_eigenvalues[_key][0].real # type: ignore
n_particles = aux_op_eigenvalues[_key][0].real
result.num_particles.append(n_particles)

if not np.isclose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def interpret(self, result: EigenstateResult) -> None:
if not isinstance(result.aux_operator_eigenvalues, list):
aux_operator_eigenvalues = [result.aux_operator_eigenvalues]
else:
aux_operator_eigenvalues = result.aux_operator_eigenvalues # type: ignore[assignment]
aux_operator_eigenvalues = result.aux_operator_eigenvalues

num_modes = len(self._basis._num_modals_per_mode)

Expand All @@ -114,7 +114,7 @@ def interpret(self, result: EigenstateResult) -> None:
for mode in range(num_modes):
_key = str(mode) if isinstance(aux_op_eigenvalues, dict) else mode
if aux_op_eigenvalues[_key] is not None:
occ_modals.append(aux_op_eigenvalues[_key][0].real) # type: ignore
occ_modals.append(aux_op_eigenvalues[_key][0].real)
else:
occ_modals.append(None)
result.num_occupied_modals_per_mode.append(occ_modals) # type: ignore
result.num_occupied_modals_per_mode.append(occ_modals)
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def second_q_ops(self) -> ListOrDictType[VibrationalOp]:
ops.append(ints.to_second_q_op())

if not settings.dict_aux_operators:
return [sum(ops)] # type: ignore[list-item]
return [sum(ops)]

return {self.name: sum(ops)} # type: ignore[dict-item]
return {self.name: sum(ops)}

def interpret(self, result: EigenstateResult) -> None:
"""Interprets an :class:`~qiskit_nature.results.EigenstateResult` in this property's context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _transform_property(self, prop: Property) -> Property:
transformed_property._shift[self.__class__.__name__] = e_inactive

elif isinstance(prop, ParticleNumber):
p_n = cast(ParticleNumber, prop)
p_n = prop
active_occ_alpha = p_n.occupation_alpha[self._active_orbs_indices]
active_occ_beta = p_n.occupation_beta[self._active_orbs_indices]
transformed_property = ParticleNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""The Freeze-Core Reduction interface."""

from typing import cast, List, Optional, Tuple
from typing import List, Optional, Tuple

from qiskit_nature import QiskitNatureError
from qiskit_nature.properties.second_quantization.electronic import ElectronicStructureDriverResult
Expand Down Expand Up @@ -78,7 +78,6 @@ def _determine_active_space(
"The FreezeCoreTransformer requires an `ElectronicStructureDriverResult`, not a "
f"property of type {type(grouped_property)}."
)
grouped_property = cast(ElectronicStructureDriverResult, grouped_property)

molecule = grouped_property.molecule
particle_number = grouped_property.get_property("ParticleNumber")
Expand Down

0 comments on commit d49ed8b

Please sign in to comment.