Skip to content

Commit 1b01c6c

Browse files
author
kyle cooper
committed
toc
1 parent f964e95 commit 1b01c6c

1 file changed

Lines changed: 25 additions & 65 deletions

File tree

README.md

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,6 @@ We also include an implementation of R-SPLINE, which can be cited as follows:
1111

1212
Wang, H., Pasupathy, R., and Schmeiser, B. W. 2013. Integer-ordered simulation optimization using R-SPLINE: Retrospective Search with Piecewise-Linear Interpolation and Neighborhood Enumeration. ACM Transactions on Modeling and Computer Simulation, Vol. 23, No. 3, Article 17 (July 2013), 24 pages. DOI:http://dx.doi.org/10.1145/2499913.2499916
1313

14-
15-
Table of Contents
16-
=================
17-
18-
* [PyMOSO](#pymoso)
19-
* [Reference](#reference)
20-
* [Installation](#installation)
21-
* [Dependency: Python 3.6 ](#dependency-python-36)
22-
* [Install from PyPI](#install-from-pypi)
23-
* [Install latest trunk version from git](#install-latest-trunk-version-from-git)
24-
* [Install from source](#install-from-source)
25-
* [CLI](#cli)
26-
* [CLI: listitems](#cli-listitems)
27-
* [CLI: solve](#cli-solve)
28-
* [CLI: testsolve](#cli-testsolve)
29-
* [CLI: Output](#cli-output)
30-
* [Table of options for solve and testsolve](#table-of-options-for-solve-and-testsolve)
31-
* [Table of algorithm-specific parameters](#table-of-algorithm-specific-parameters)
32-
* [Programming guide](#programming-guide)
33-
* [Implementing a problem in PyMOSO](#implementing-a-problem-in-pymoso)
34-
* [Template for implementing problems (myproblem.py)](#template-for-implementing-problems-myproblempy)
35-
* [Using rng](#using-rng)
36-
* [Simple example problem](#simple-example-problem)
37-
* [Implementing a Tester in PyMOSO](#implementing-a-tester-in-pymoso)
38-
* [Implementing algorithms in PyMOSO](#implementing-algorithms-in-pymoso)
39-
* [Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)](#example-moso-algorithm-in-pymoso-that-uses-rle-to-ensure-convergence-myaccelpy)
40-
* [Example of an RA algorithm (myraalg.py)](#example-of-an-ra-algorithm-myraalgpy)
41-
* [Example of a MOSO algorithm (mymoso.py)](#example-of-a-moso-algorithm-mymosopy)
42-
* [Class Structure and internal functions](#class-structure-and-internal-functions)
43-
* [Useful snippets for implementing RA algorithms](#useful-snippets-for-implementing-ra-algorithms)
44-
* [Sample a point](#sample-a-point)
45-
* [Sample the point's neighbors](#sample-the-points-neighbors)
46-
* [argsort the points by 1st objective](#argsort-the-points-by-1st-objective)
47-
* [choose the minimizer and its objectives](#choose-the-minimizer-and-its-objectives)
48-
* [Use SPLINE to get a local minimizer](#use-spline-to-get-a-local-minimizer)
49-
* [Get the non-dominated subset of every visited point](#get-the-non-dominated-subset-of-every-visited-point)
50-
* [Randomly choose points from the subset](#randomly-choose-points-from-the-subset)
51-
* [Using PyMOSO in Python programs](#using-pymoso-in-python-programs)
52-
* [Solve example](#solve-example)
53-
* [TestSolve example](#testsolve-example)
54-
5514
## Installation
5615
### Dependency: Python 3.6+
5716
This software requires Python 3.6 or higher. Python can be downloaded from https://www.python.org/downloads/.
@@ -117,19 +76,19 @@ Help:
11776
test problems.
11877
```
11978
For now, PyMOSO has three commands: `listitems`, `solve`, and `testsolve`, which we explain below.
120-
##### CLI: listitems
79+
#### listitems
12180
The command `listitems` shows the PyMOSO objects (problems, testers, solvers) included in the default installation. The identifiers can be used as arguments to `solve` and `testsolve`. PyMOSO objects implemented by users will not show up when using `listitems`.
122-
##### CLI: solve
81+
#### solve
12382
The `solve` command is intended for practitioners seeking to a solve a simulation optimization problem. Three arguments are required: `<problem>`, `<solver>`, and `<x>...`. For `<problem>`, users may specify an identifier for a built-in problem. A list of such identifiers can be viewed using `listitems`. Alternatively, users may implement their own problem as a PyMOSO oracle (see the code examples below) and specify the file name.
12483
For example,
12584
`pymoso solve myproblem.py RPERLE 40 40`
12685
The `<solver>` argument again either an identifier to a built-in algorithm, or a file name for a user-implemented algorithm. The `<x>...` is a feasible starting point for the algorithm, with each component of the starting point separated by a space. Any number of the options listed above can also be specified before the arguments. At the end of this section, we list the options and provide more detailed explanations. The `<x>` argument cannot take negative numbers from the command line. Use PyMOSO in a Python program if a negative starting point is required (see examples below).
127-
##### CLI: testsolve
86+
#### testsolve
12887
The `testsolve` command is intended for researchers creating new simulation optimization algorithms. Two arguments are required: `<tester>` and `<solver>`. Similar to `solve`, `<tester>` and `<solver>` may be specified as identifiers to built-in testers or as Python files containing user-implemented objects. Specifying `<x>...` is optional: testers may implement a method to generate feasible starting points. If not, then `<x>...` can be provided.
129-
##### CLI: Output
88+
#### Output
13089
Both `solve` and `testsolve` create a subdirectory within the working directory in which the generated results are saved. In the case of `solve`, the directory typically contains two files: a file containing metadata such as the arguments and options specified, date, run time, and more. The second file contains the solution generated by the chosen solver. If applicable, an error file may be generated. If an error is generated, users may send the metadata file, the error file, and any user-implemented PyMOSO objects to us for assistance. In the case of `testsolve`, the file containing the solution will instead contain multiple solutions, with the last row containing the end solution returned by the algorithm. The intermediate solutions are provided to give a researchers a sense of how the algorithm progresses. If the `--isp` option is specified to generate multiple independent sample path solutions, there will a solution file for every independent sample path. If the `--metric` options is specified, the metric defined in the `<tester>` will be computed on the solutions and saved in a separate file. All available options to `solve` or `testsolve` are specified below.
13190

132-
##### Table of options for solve and testsolve
91+
#### Table of options for solve and testsolve
13392
| Option | Description |
13493
| ----------- | ----------- |
13594
|`--budget=B`| The simulation budget limits the number of simulations the algorithm can use to generate a solution. `B` should be a natural number. |
@@ -143,7 +102,7 @@ Both `solve` and `testsolve` create a subdirectory within the working directory
143102
|`--param <param> <val>`| Specify a parameter by name and value. These are algorithm-specific parameters.|
144103

145104

146-
##### Table of algorithm-specific parameters
105+
#### Table of algorithm-specific parameters
147106
| Algorithm | Parameter | Default | Description |
148107
| --------- | --------- | ------- | ----------- |
149108
| `RPERLE`, `RMINRLE`, `RPE`, `RSPLINE` | `mconst` | `2` | Sets the initial sample size, and subsequent schedule of sample sizes. |
@@ -158,7 +117,7 @@ Users can implement their own problems in PyMOSO using `myproblem.py` below as t
158117
1. `True` or `False` depending on if `x` is feasible to the problem.
159118
1. A tuple of length `self.num_obj` containing the value of each objective.
160119

161-
##### Template for implementing problems (myproblem.py)
120+
#### Template for implementing problems (myproblem.py)
162121
```python
163122
# import the Oracle base class
164123
from pymoso.chnbase import Oracle
@@ -182,7 +141,7 @@ class MyProblem(Oracle):
182141
return is_feas, (obj1, obj2)
183142
```
184143

185-
##### Using `rng`
144+
#### Using `rng`
186145
Though not required, users may use the `rng` random number generator object. Doing so allows algorithms to take advantage of common random numbers and ensures parallelized simulation replications are independent. The implementation of the `rng` object is a subclass of Python's `random.Random()` where the underlying generator is `mrg32k3a`. Thus, Python's own `random` documentation applies to `rng` and can be found at https://docs.python.org/3/library/random.html. We follow the example of L'Ecuyer et al. 2001 for `mrg32k3a` and implementing its independent streams and substreams.
187146

188147
L'Ecuyer, P., Simard, R., Chen, E. J., Kelton, W. D. An Object-Oriented Random-Number Package with Many Long Streams and Substreams. (2002). Operations Research, 50(6), 1073-1075.
@@ -195,7 +154,7 @@ To be compatible with common random numbers, users can simply use the generator.
195154

196155
To ensure independent sampling of observations, PyMOSO "jumps" the stream after every observation by a fixed amount of `pow(2, 76)`. Thus, we require that every simulation observation use fewer than `pow(2, 76)` random numbers for users needing independent replications. We ensure independence among parallel replications by "giving" each processor an `rng` each of which are `pow(2, 127)` randomn numbers apart. When using the included algorithms, each retrospective iteration begins with a new independent stream `pow(2, 127)` from the beginning of the previous stream, where PyMOSO sets the previous stream to account for any parallel streams used within a retrospective iteration. thus, in a given retrospective iteration, a user may simulate 100 million points at a sample size of 1 million, without common random numbers, and easily not reach the limit. For researchers using `testsolve`, the observations cannot be taken in parallel, but independent algorithm instances can be. To ensure the instances remain independent, researchers should set the budget such that the included algorithms do not surpass 200 retrospective iterations. For reference, on default settings, the sample size at every point in the 200th iteration is almost 380 million.
197156

198-
##### Simple example problem
157+
#### Simple example problem
199158
```python
200159
def g(self, x, rng):
201160
'''Check feasibility and simulate objective values.'''
@@ -290,7 +249,7 @@ Users can leverage internal PyMOSO structures to implement new algorithms. It is
290249

291250
Pasupathy R, Ghosh S (2013) Simulation optimization: a concise overview and implementation guide. Topaloglu H, ed., TutORials in Operations Research, chapter 7, 122–150 (Catonsville, MD: INFORMS), URL http://dx.doi.org/10.1287/educ.2013.0118.
292251

293-
##### Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)
252+
#### Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)
294253
```python
295254
from pymoso.chnbase import RLESolver
296255

@@ -309,7 +268,7 @@ Programmers can use pymoso to create new algorithms that use RLE for convergence
309268
Once implmented, solve a problem using the accelerator as follows.
310269
`pymoso solve myproblem.py myaccel.py 97`
311270

312-
##### Example of an RA algorithm (myraalg.py)
271+
#### Example of an RA algorithm (myraalg.py)
313272
```python
314273
from pymoso.chnbase import RASolver
315274

@@ -327,7 +286,7 @@ More generally, algorithm designers can quickly implement any retrospective appr
327286

328287
`pymoso solve myproblem.py myraalg.py 97`
329288

330-
##### Example of a MOSO algorithm (mymoso.py)
289+
#### Example of a MOSO algorithm (mymoso.py)
331290
```python
332291
from pymoso.chnbase import MOSOSolver
333292

@@ -352,10 +311,11 @@ class MyMOSO(MOSOSolver):
352311
353312
PyMOSO can accommodate any simulation optimization algorithm by implementing the `solve` function of a `MOSOSolver` class as shown. It does not have to be a multi-objective algorithm. PyMOSO will require users to send an initial feasible point `x0` whether or not the algorithm needs it. It is accessed through `self.x0` which is a tuple. The return value must be a Python dictionary with the keys 'itersoln', 'simcalls', and 'endseed'. 'itersoln' itself is a dictionary with a key for every iteration (or a number indicating some ordered, intermediate step of the algorithm). Similarly, `simcalls` is itself a dictionary of iteration number by cumulative number of simulations at the end of the corresponding iteration. `endseed` is a tuple of length 6 representing a new indpendent `rng` seed users can pass into the next PyMOSO invocation.
354313
355-
##### Class Structure and internal functions
314+
#### PyMOSO internals
356315
The base class `MOSOSolver` implements basic members required to solve MOSO problems. To implement a general (i.e. non-RA) MOSO algorithm in pymoso, one must subclass `MOSOSolver` and implement the `MOSOSolver.solve` function with signature `solve(self, budget)` and it must return a set, even if the set contains a single point. `RASolver` is a subclass of `MOSOSolver` which provides the machinery needed to quickly implement a retrospective approximation algorithm. To implement an RA algorithm, one must subclass `RASolver` and implement its `spsolve` method with signature `spsolve(self, warm_start)` which returns a set of points.`RLESolver`, subclass of `RASolver`, allows quick implementation of MOSO solvers that use `RLE` to ensure convergence, as shown in the example accelerator above. One only needs to implement the `accel` method of `RLESolver`. Oracles are the problems that PyMOSO can solve. Here, we provide a listing of the important objects available to pymoso programmers who are implementing MOSO algorithms.
357316
358-
| PyMOSO internals | Example | Description |
317+
##### Table of PyMOSO internals
318+
| PyMOSO internal object | Example | Description |
359319
| ------------- | ------- | ----------- |
360320
|`pymoso.prng.mrg32k3a.MRG32k3a`| `rng = MRG32k3a()` | Subclass of `random.Random()` for generating random numbers. |
361321
|`pymoso.prng.mrg32k3a.get_next_prnstream`| `prn = get_next_prnstream(seed)` | Returns a stream 2^127 places from the given `seed` |
@@ -389,7 +349,7 @@ The base class `MOSOSolver` implements basic members required to solve MOSO prob
389349
|`RLESolver.betadel` | `bd = RLESolver.betadel` | The relaxation parameter used by `RLE`. |
390350
|`RLESolver.calc_delta` | `d = RLESolver.calc_delta(nu)` | Compute the relaxation for iteration `nu`. |
391351
392-
352+
##### Table of chnutils functions
393353
| chnutils function | Example | Description |
394354
| ------------- | ------- | ----------- |
395355
|`does_weak_dominate` | `dwd = does_weak_dominate(g1, g2, rel1, rel2)` | Returns true if `g1[i] - rel1[i] <= g2[i] + rel2[i]` for every `i`.
@@ -400,9 +360,9 @@ The base class `MOSOSolver` implements basic members required to solve MOSO prob
400360
|`get_nbors` | `nbors = get_nbors(x, r)` | Return the set of points no farther than `r` from `x` and exclude `x`. |
401361
|`get_setnbors` | `nbors = get_setnbors(S, r)` | Excluding points in the set `S`, return `get_nbors(s, r)` for every `s` in `S`. |
402362
403-
##### Useful snippets for implementing RA algorithms
363+
#### Useful snippets for implementing RA algorithms
404364
These snippets will work within the `spsolve` and/or the `accel` functions in the `myaccel.py` and `myraalg.py` examples above.
405-
###### Sample a point
365+
##### Sample a point
406366
```python
407367
from pymoso.chnutils import get_nbors
408368
# pretend x has not yet been visited in this RA iteration and is feasible
@@ -425,7 +385,7 @@ isfeas, fx, se = self.estimate(x)
425385
calls_used = self.num_calls - start_num_calls
426386
print(calls_used == 0) # True
427387
```
428-
###### Sample the point's neighbors
388+
##### Sample the point's neighbors
429389
```python
430390
# neighborhood radiuss
431391
r = self.nbor_rad
@@ -437,17 +397,17 @@ for n in nbors:
437397
# upsample also returns the feasible subset
438398
nbors = self.upsample(nbors)
439399
```
440-
###### argsort the points by 1st objective
400+
##### argsort the points by 1st objective
441401
```python
442402
# 0 index for first objective
443403
sorted_feas = sorted(nbors | {x}, key=lambda t: self.gbar[t][0])
444404
```
445-
###### choose the minimizer and its objectives
405+
##### choose the minimizer and its objectives
446406
```python
447407
xmin = sorted_feas[0]
448408
fxmin = self.gbar[x]
449409
```
450-
###### Use SPLINE to get a local minimizer
410+
##### Use SPLINE to get a local minimizer
451411
```python
452412
# no constraints and minimize the 2nd objective
453413
x0 = (2, 2, 2)
@@ -456,20 +416,20 @@ isfeas, fx, sex = self.estimate(x0)
456416
_, xmin, fxmin, sexmin = self.spline(x0, float('inf'), 1, 0)
457417
print(self.gbar[xmin] == fxmin) # True
458418
```
459-
###### Get the non-dominated subset of every visited point
419+
##### Get the non-dominated subset of every visited point
460420
```python
461421
from chnutils import get_nondom
462422
nondom = get_nondom(self.gbar)
463423
```
464-
###### Randomly choose points from the subset
424+
##### Randomly choose points from the subset
465425
```python
466426
solver_rng = self.sprn
467427
# pick 5 points -- returns a list, not a set.
468428
ran_pts = solver_rng.sample(list(nondom), 5)
469429
one_in_five = solver_rng.choice(ran_pts)
470430
```
471431
472-
### Using PyMOSO in Python programs
432+
## Using PyMOSO in Python programs
473433
### Solve example
474434
```python
475435
# import the solve function

0 commit comments

Comments
 (0)