Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try moving code-sample into README #1150

Merged
merged 8 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,47 @@ Install libEnsemble and its dependencies from PyPI_ using pip::

Other install methods are described in the docs_.

Basic Usage
===========

Create an ``Ensemble``, then customize it with general settings, simulation and generator parameters,
and an exit condition. Run the following via ``python this_file.py --comms local --nworkers 4``:

.. code-block:: python

import numpy as np

from libensemble import Ensemble
from libensemble.gen_funcs.sampling import uniform_random_sample
from libensemble.sim_funcs.six_hump_camel import six_hump_camel
from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs
from libensemble.tools import add_unique_random_streams

if __name__ == "__main__":
sampling = Ensemble(parse_args=True)
sampling.sim_specs = SimSpecs(
sim_f=six_hump_camel,
inputs=["x"],
outputs=[("f", float)],
)
sampling.gen_specs = GenSpecs(
gen_f=uniform_random_sample,
outputs=[("x", float, (2,))],
user={
"gen_batch_size": 500,
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
)

sampling.persis_info = add_unique_random_streams({}, sampling.nworkers + 1)
sampling.exit_criteria = ExitCriteria(sim_max=101)
sampling.run()
sampling.save_output(__file__)

if sampling.is_manager:
print("Some output data:\n", sampling.H[["x", "f"]][:10])

Resources
=========

Expand Down
44 changes: 0 additions & 44 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
.. include:: ../README.rst
:start-after: after_badges_rst_tag

Basic Usage
===========

.. basic_usage

Create an ``Ensemble``, then customize with general settings, simulation and generator parameters,
and an exit condition. Run the following via ``python this_file.py --comms local --nworkers 4``:

.. code-block:: python
:linenos:

import numpy as np

from libensemble import Ensemble
from libensemble.gen_funcs.sampling import uniform_random_sample
from libensemble.sim_funcs.six_hump_camel import six_hump_camel
from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs
from libensemble.tools import add_unique_random_streams

if __name__ == "__main__":
sampling = Ensemble(parse_args=True)
sampling.sim_specs = SimSpecs(
sim_f=six_hump_camel,
inputs=["x"],
outputs=[("f", float)],
)
sampling.gen_specs = GenSpecs(
gen_f=uniform_random_sample,
outputs=[("x", float, (2,))],
user={
"gen_batch_size": 500,
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
)

sampling.persis_info = add_unique_random_streams({}, sampling.nworkers + 1)
sampling.exit_criteria = ExitCriteria(sim_max=101)
sampling.run()
sampling.save_output(__file__)

if sampling.is_manager:
print("Some output data:\n", sampling.H[["x", "f"]][:10])

See the :doc:`tutorial<tutorials/local_sine_tutorial>` for a step-by-step beginners guide.

See the `user guide`_ for more information.
Expand Down
2 changes: 2 additions & 0 deletions libensemble/tests/unit_tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def test_procs_and_machinefile_logic():
else:
task = exctr.submit(calc_type="sim", num_procs=6, num_nodes=2, procs_per_node=3, app_args=args_for_sim)
task = polling_loop(exctr, task, delay=0.05)
time.sleep(0.25)
assert task.finished, "task.finished should be True. Returned " + str(task.finished)
assert task.state == "FINISHED", "task.state should be FINISHED. Returned " + str(task.state)

Expand All @@ -431,6 +432,7 @@ def test_procs_and_machinefile_logic():
task = exctr.submit(calc_type="sim", num_nodes=2, procs_per_node=3, app_args=args_for_sim)
assert 1
task = polling_loop(exctr, task, delay=0.05)
time.sleep(0.25)
assert task.finished, "task.finished should be True. Returned " + str(task.finished)
assert task.state == "FINISHED", "task.state should be FINISHED. Returned " + str(task.state)

Expand Down
Loading