qiskit_optimization/problems/quadratic_program.py
def read_from_lp_file(self, filename: str) -> None:
        """Loads the quadratic program from a LP file.

        Args:
            filename: The filename of the file to be loaded.

        Raises:
            FileNotFoundError: If the file does not exist.
            MissingOptionalLibraryError: If CPLEX is not installed.

        Note:
            This method requires CPLEX to be installed and present in ``PYTHONPATH``.
        """
        try:
            import cplex  # pylint: disable=unused-import
        except ImportError as ex:
            raise MissingOptionalLibraryError(
                libname="CPLEX",
                name="QuadraticProgram.read_from_lp_file",
                pip_install="pip install 'qiskit-optimization[cplex]'",
            ) from ex

        def _parse_problem_name(filename: str) -> str:
            # Because docplex model reader uses the base name as model name,
            # we parse the model name in the LP file manually.
            # https://ibmdecisionoptimization.github.io/docplex-doc/mp/docplex.mp.model_reader.html
            prefix = "\\Problem name:"
            model_name = ""
            with open(filename, encoding="utf8") as file:
                for line in file:
                    if line.startswith(prefix):
                        model_name = line[len(prefix) :].strip()
                    if not line.startswith("\\"):
                        break
            return model_name

        # pylint: disable=cyclic-import
        from ..translators.docplex_mp import from_docplex_mp

        model = ModelReader().read(filename, model_name=_parse_problem_name(filename))
        other = from_docplex_mp(model)
        self._copy_from(other, include_name=True)
Loads the quadratic program from a LP file.

        Args:
            filename: The filename of the file to be loaded.

        Raises:
            FileNotFoundError: If the file does not exist.
            MissingOptionalLibraryError: If CPLEX is not installed.

        Note:
            This method requires CPLEX to be installed and present in ``PYTHONPATH``.
        
Loads the quadratic program from a LP file.
Loads the quadratic program from a LP file .
def read_from_lp_file(self, filename: str) -> None:
        try:
            import cplex  
        except ImportError as ex:
            raise MissingOptionalLibraryError(
                libname="CPLEX",
                name="QuadraticProgram.read_from_lp_file",
                pip_install="pip install 'qiskit-optimization[cplex]'",
            ) from ex
        def _parse_problem_name(filename: str) -> str:
            prefix = "\\Problem name:"
            model_name = ""
            with open(filename, encoding="utf8") as file:
                for line in file:
                    if line.startswith(prefix):
                        model_name = line[len(prefix) :].strip()
                    if not line.startswith("\\"):
                        break
            return model_name
        from ..translators.docplex_mp import from_docplex_mp
        model = ModelReader().read(filename, model_name=_parse_problem_name(filename))
        other = from_docplex_mp(model)
        self._copy_from(other, include_name=True)
def read_from_lp_file ( self , filename : str ) -> None : try : import cplex except ImportError as ex : raise MissingOptionalLibraryError ( libname = "CPLEX" , name = "QuadraticProgram.read_from_lp_file" , pip_install = "pip install 'qiskit-optimization[cplex]'" , ) from ex def _parse_problem_name ( filename : str ) -> str : prefix = "\\Problem name:" model_name = "" with open ( filename , encoding = "utf8" ) as file : for line in file : if line . startswith ( prefix ) : model_name = line [ len ( prefix ) : ] . strip ( ) if not line . startswith ( "\\" ) : break return model_name from . . translators . docplex_mp import from_docplex_mp model = ModelReader ( ) . read ( filename , model_name = _parse_problem_name ( filename ) ) other = from_docplex_mp ( model ) self . _copy_from ( other , include_name = True )
Loads the quadratic program from a LP file.
Loads the quadratic program from a LP file .
"""Loads the quadratic program from a LP file.

        Args:
            filename: The filename of the file to be loaded.

        Raises:
            FileNotFoundError: If the file does not exist.
            MissingOptionalLibraryError: If CPLEX is not installed.

        Note:
            This method requires CPLEX to be installed and present in ``PYTHONPATH``.
        """ # pylint: disable=unused-import # Because docplex model reader uses the base name as model name, # we parse the model name in the LP file manually. # https://ibmdecisionoptimization.github.io/docplex-doc/mp/docplex.mp.model_reader.html # pylint: disable=cyclic-import
If the file does not exist.
If the file does not exist .
FileNotFoundError
If CPLEX is not installed.
If CPLEX is not installed .
MissingOptionalLibraryError
self
filename
str
The filename of the file to be loaded.
The filename of the file to be loaded .