Skip to content

Commit

Permalink
Create platypus script
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Oct 4, 2024
1 parent 43d45a4 commit b63bee9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
26 changes: 13 additions & 13 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ see all available options, run:

.. code:: bash
python -m platypus --help
platypus --help
Solve
-----
Expand All @@ -16,14 +16,14 @@ Solve executes the given algorithm on a problem, saving the final approximation

.. code:: bash
python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 --output NSGAII_DTLZ2.set
platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 --output NSGAII_DTLZ2.set
Additional arguments can be provided, such as setting the ``population_size`` as demonstrated below.
Note that only arguments with primitive types are supported.

.. code:: bash
python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 population_size=250
platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 population_size=250
::

Expand All @@ -39,7 +39,7 @@ the hypervolume using a reference set for normalization:

.. code:: bash
python -m platypus hypervolume --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set
platypus hypervolume --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set
which outputs:

Expand All @@ -54,8 +54,8 @@ The results can be filtered to remove any dominated, infeasible, or duplicate so

.. code:: bash
python -m platypus filter --output NSGAII_DTLZ2_unique.set --feasible --unique NSGAII_DTLZ2.set
python -m platypus filter --output NSGAII_DTLZ2_epsilons.set --epsilons 0.01,0.01 NSGAII_DTLZ2.set
platypus filter --output NSGAII_DTLZ2_unique.set --feasible --unique NSGAII_DTLZ2.set
platypus filter --output NSGAII_DTLZ2_epsilons.set --epsilons 0.01,0.01 NSGAII_DTLZ2.set
Normalization
-------------
Expand All @@ -67,8 +67,8 @@ the normalized solutions:

.. code:: bash
python -m platypus normalize --output NSGAII_DTLZ2_normalized.set --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set
python -m platypus normalize --output NSGAII_DTLZ2_normalized.set --minimum 0.0,0.0 --maximum 1.0,1.0 NSGAII_DTLZ2.set
platypus normalize --output NSGAII_DTLZ2_normalized.set --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set
platypus normalize --output NSGAII_DTLZ2_normalized.set --minimum 0.0,0.0 --maximum 1.0,1.0 NSGAII_DTLZ2.set
Plotting
--------
Expand All @@ -77,8 +77,8 @@ For 2 and 3 objectives, we can also generate a plot, either interactive or savin

.. code:: bash
python -m platypus plot NSGAII_DTLZ2.set
python -m platypus plot --output NSGAII_DTLZ2.png NSGAII_DTLZ2.set
platypus plot NSGAII_DTLZ2.set
platypus plot --output NSGAII_DTLZ2.png NSGAII_DTLZ2.set
Combining or Chaining Commands
------------------------------
Expand All @@ -89,6 +89,6 @@ as demonstrated below:

.. code:: bash
python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 | \
python -m platypus filter --epsilons 0.01,0.01 | \
python -m platypus plot
platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 | \
platypus filter --epsilons 0.01,0.01 | \
platypus plot
7 changes: 5 additions & 2 deletions platypus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
type_cast)


def main(input):
def main(input=None):
"""The main entry point for the Platypus CLI."""
LOGGER = logging.getLogger("Platypus")

if input is None:
input = sys.argv[1:]

def load_set(file):
"""Loads input file from stdin or file."""
if file is None:
Expand Down Expand Up @@ -264,4 +267,4 @@ def debug_inputs(args):
plt.show()

if __name__ == "__main__":
main(sys.argv[1:])
main()
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ test = ["pytest", "mock", "flake8", "flake8-pyproject", "numpy", "matplotlib", "
docs = ["sphinx", "sphinx-rtd-theme"]
full = ["mpi4py", "Platypus-Opt[test]", "Platypus-Opt[docs]"]

[project.scripts]
platypus = "platypus.__main__:main"

[tool.setuptools.dynamic]
version = {attr = "platypus.__version__"}

Expand Down

0 comments on commit b63bee9

Please sign in to comment.