Skip to content

Commit 28a365d

Browse files
committed
Move kernel examples into OnlineDocs/src
1 parent f3a9b1f commit 28a365d

File tree

10 files changed

+63
-62
lines changed

10 files changed

+63
-62
lines changed

doc/OnlineDocs/explanation/experimental/kernel/index.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The :python:`pyomo.kernel` library is an experimental modeling interface designe
2121

2222
Models built from :python:`pyomo.kernel` components are fully compatible with the standard solver interfaces included with Pyomo. A minimal example script that defines and solves a model is shown below.
2323

24-
.. literalinclude:: examples/kernel_solving.py
24+
.. literalinclude:: /src/kernel/examples/kernel_solving.py
2525
:language: python
2626

2727
Notable Improvements
@@ -32,7 +32,7 @@ More Control of Model Structure
3232

3333
Containers in :python:`pyomo.kernel` are analogous to indexed components in :python:`pyomo.environ`. However, :python:`pyomo.kernel` containers allow for additional layers of structure as they can be nested within each other as long as they have compatible categories. The following example shows this using :python:`pyomo.kernel.variable` containers.
3434

35-
.. literalinclude:: examples/kernel_containers_all.spy
35+
.. literalinclude:: /src/kernel/examples/kernel_containers_all.spy
3636
:language: python
3737

3838
As the next section will show, the standard modeling component containers are also compatible with user-defined classes that derive from the existing modeling components.
@@ -58,21 +58,21 @@ The next series of examples goes into more detail on how to implement derived co
5858

5959
The following code block shows a class definition for a non-negative variable, starting from :python:`pyomo.kernel.variable` as a base class.
6060

61-
.. literalinclude:: examples/kernel_subclassing_Nonnegative.spy
61+
.. literalinclude:: /src/kernel/examples/kernel_subclassing_Nonnegative.spy
6262
:language: python
6363

6464
The :python:`NonNegativeVariable` class prevents negative values from being stored into its lower bound during initialization or later on through assignment statements (e.g, :python:`x.lb = -1` fails). Note that the :python:`__slots__ == ()` line at the beginning of the class definition is optional, but it is recommended if no additional data members are necessary as it reduces the memory requirement of the new variable type.
6565

6666
The next code block defines a custom variable container called :python:`Point` that represents a 3-dimensional point in Cartesian space. The new type derives from the :python:`pyomo.kernel.variable_tuple` container and uses the :python:`NonNegativeVariable` type we defined previously in the `z` coordinate.
6767

68-
.. literalinclude:: examples/kernel_subclassing_Point.spy
68+
.. literalinclude:: /src/kernel/examples/kernel_subclassing_Point.spy
6969
:language: python
7070

7171
The :python:`Point` class can be treated like a tuple storing three variables, and it can be placed inside of other variable containers or added as attributes to blocks. The property methods included in the class definition provide an additional syntax for accessing the three variables it stores, as the next code example will show.
7272

7373
The following code defines a class for building a convex second-order cone constraint from a :python:`Point` object. It derives from the :python:`pyomo.kernel.constraint` class, overriding the constructor to build the constraint expression and utilizing the property methods on the point class to increase readability.
7474

75-
.. literalinclude:: examples/kernel_subclassing_SOC.spy
75+
.. literalinclude:: /src/kernel/examples/kernel_subclassing_SOC.spy
7676
:language: python
7777

7878

@@ -81,12 +81,12 @@ Reduced Memory Usage
8181

8282
The :python:`pyomo.kernel` library offers significant opportunities to reduce memory requirements for highly structured models. The situation where this is most apparent is when expressing a model in terms of many small blocks consisting of singleton components. As an example, consider expressing a model consisting of a large number of voltage transformers. One option for doing so might be to define a `Transformer` component as a subclass of :python:`pyomo.kernel.block`. The example below defines such a component, including some helper methods for connecting input and output voltage variables and updating the transformer ratio.
8383

84-
.. literalinclude:: examples/transformer_kernel.spy
84+
.. literalinclude:: /src/kernel/examples/transformer_kernel.spy
8585
:language: python
8686

8787
A simplified version of this using :python:`pyomo.environ` components might look like what is below.
8888

89-
.. literalinclude:: examples/transformer_aml.spy
89+
.. literalinclude:: /src/kernel/examples/transformer_aml.spy
9090
:language: python
9191

9292
The transformer expressed using :python:`pyomo.kernel` components requires roughly 2 KB of memory, whereas the :python:`pyomo.environ` version requires roughly 8.4 KB of memory (an increase of more than 4x). Additionally, the :python:`pyomo.kernel` transformer is fully compatible with all existing :python:`pyomo.kernel` block containers.
@@ -142,7 +142,7 @@ instantiation. The first method is to directly instantiate a
142142
conic constraint object, providing all necessary input
143143
variables:
144144

145-
.. literalinclude:: examples/conic_Class.spy
145+
.. literalinclude:: /src/kernel/examples/conic_Class.spy
146146
:language: python
147147

148148
This method may be limiting if utilizing the Mosek solver as
@@ -164,5 +164,5 @@ constraint, as well as auxiliary constraints that link the
164164
inputs (that are not :python:`None`) to the auxiliary
165165
variables. Example:
166166

167-
.. literalinclude:: examples/conic_Domain.spy
167+
.. literalinclude:: /src/kernel/examples/conic_Domain.spy
168168
:language: python

doc/OnlineDocs/explanation/experimental/kernel/syntax_comparison.rst

+52-52
Original file line numberDiff line numberDiff line change
@@ -12,119 +12,119 @@ Syntax Comparison Table (pyomo.kernel vs pyomo.environ)
1212
- **pyomo.environ**
1313

1414
* - **Import**
15-
- .. literalinclude:: examples/kernel_example_Import_Syntax.spy
15+
- .. literalinclude:: /src/kernel/examples/kernel_example_Import_Syntax.spy
1616
:language: python
17-
- .. literalinclude:: examples/aml_example_Import_Syntax.spy
17+
- .. literalinclude:: /src/kernel/examples/aml_example_Import_Syntax.spy
1818
:language: python
1919
* - **Model** [#models_fn]_
20-
- .. literalinclude:: examples/kernel_example_AbstractModels.spy
20+
- .. literalinclude:: /src/kernel/examples/kernel_example_AbstractModels.spy
2121
:language: python
22-
.. literalinclude:: examples/kernel_example_ConcreteModels.spy
22+
.. literalinclude:: /src/kernel/examples/kernel_example_ConcreteModels.spy
2323
:language: python
24-
- .. literalinclude:: examples/aml_example_AbstractModels.spy
24+
- .. literalinclude:: /src/kernel/examples/aml_example_AbstractModels.spy
2525
:language: python
26-
.. literalinclude:: examples/aml_example_ConcreteModels.spy
26+
.. literalinclude:: /src/kernel/examples/aml_example_ConcreteModels.spy
2727
:language: python
2828
* - **Set** [#sets_fn]_
29-
- .. literalinclude:: examples/kernel_example_Sets_1.spy
29+
- .. literalinclude:: /src/kernel/examples/kernel_example_Sets_1.spy
3030
:language: python
31-
.. literalinclude:: examples/kernel_example_Sets_2.spy
31+
.. literalinclude:: /src/kernel/examples/kernel_example_Sets_2.spy
3232
:language: python
33-
- .. literalinclude:: examples/aml_example_Sets_1.spy
33+
- .. literalinclude:: /src/kernel/examples/aml_example_Sets_1.spy
3434
:language: python
35-
.. literalinclude:: examples/aml_example_Sets_2.spy
35+
.. literalinclude:: /src/kernel/examples/aml_example_Sets_2.spy
3636
:language: python
3737
* - **Parameter** [#parameters_fn]_
38-
- .. literalinclude:: examples/kernel_example_Parameters_single.spy
38+
- .. literalinclude:: /src/kernel/examples/kernel_example_Parameters_single.spy
3939
:language: python
40-
.. literalinclude:: examples/kernel_example_Parameters_dict.spy
40+
.. literalinclude:: /src/kernel/examples/kernel_example_Parameters_dict.spy
4141
:language: python
42-
.. literalinclude:: examples/kernel_example_Parameters_list.spy
42+
.. literalinclude:: /src/kernel/examples/kernel_example_Parameters_list.spy
4343
:language: python
44-
- .. literalinclude:: examples/aml_example_Parameters_single.spy
44+
- .. literalinclude:: /src/kernel/examples/aml_example_Parameters_single.spy
4545
:language: python
46-
.. literalinclude:: examples/aml_example_Parameters_dict.spy
46+
.. literalinclude:: /src/kernel/examples/aml_example_Parameters_dict.spy
4747
:language: python
48-
.. literalinclude:: examples/aml_example_Parameters_list.spy
48+
.. literalinclude:: /src/kernel/examples/aml_example_Parameters_list.spy
4949
:language: python
5050
* - **Variable**
51-
- .. literalinclude:: examples/kernel_example_Variables_single.spy
51+
- .. literalinclude:: /src/kernel/examples/kernel_example_Variables_single.spy
5252
:language: python
53-
.. literalinclude:: examples/kernel_example_Variables_dict.spy
53+
.. literalinclude:: /src/kernel/examples/kernel_example_Variables_dict.spy
5454
:language: python
55-
.. literalinclude:: examples/kernel_example_Variables_list.spy
55+
.. literalinclude:: /src/kernel/examples/kernel_example_Variables_list.spy
5656
:language: python
57-
- .. literalinclude:: examples/aml_example_Variables_single.spy
57+
- .. literalinclude:: /src/kernel/examples/aml_example_Variables_single.spy
5858
:language: python
59-
.. literalinclude:: examples/aml_example_Variables_dict.spy
59+
.. literalinclude:: /src/kernel/examples/aml_example_Variables_dict.spy
6060
:language: python
61-
.. literalinclude:: examples/aml_example_Variables_list.spy
61+
.. literalinclude:: /src/kernel/examples/aml_example_Variables_list.spy
6262
:language: python
6363
* - **Constraint**
64-
- .. literalinclude:: examples/kernel_example_Constraints_single.spy
64+
- .. literalinclude:: /src/kernel/examples/kernel_example_Constraints_single.spy
6565
:language: python
66-
.. literalinclude:: examples/kernel_example_Constraints_dict.spy
66+
.. literalinclude:: /src/kernel/examples/kernel_example_Constraints_dict.spy
6767
:language: python
68-
.. literalinclude:: examples/kernel_example_Constraints_list.spy
68+
.. literalinclude:: /src/kernel/examples/kernel_example_Constraints_list.spy
6969
:language: python
70-
- .. literalinclude:: examples/aml_example_Constraints_single.spy
70+
- .. literalinclude:: /src/kernel/examples/aml_example_Constraints_single.spy
7171
:language: python
72-
.. literalinclude:: examples/aml_example_Constraints_dict.spy
72+
.. literalinclude:: /src/kernel/examples/aml_example_Constraints_dict.spy
7373
:language: python
74-
.. literalinclude:: examples/aml_example_Constraints_list.spy
74+
.. literalinclude:: /src/kernel/examples/aml_example_Constraints_list.spy
7575
:language: python
7676
* - **Expression**
77-
- .. literalinclude:: examples/kernel_example_Expressions_single.spy
77+
- .. literalinclude:: /src/kernel/examples/kernel_example_Expressions_single.spy
7878
:language: python
79-
.. literalinclude:: examples/kernel_example_Expressions_dict.spy
79+
.. literalinclude:: /src/kernel/examples/kernel_example_Expressions_dict.spy
8080
:language: python
81-
.. literalinclude:: examples/kernel_example_Expressions_list.spy
81+
.. literalinclude:: /src/kernel/examples/kernel_example_Expressions_list.spy
8282
:language: python
83-
- .. literalinclude:: examples/aml_example_Expressions_single.spy
83+
- .. literalinclude:: /src/kernel/examples/aml_example_Expressions_single.spy
8484
:language: python
85-
.. literalinclude:: examples/aml_example_Expressions_dict.spy
85+
.. literalinclude:: /src/kernel/examples/aml_example_Expressions_dict.spy
8686
:language: python
87-
.. literalinclude:: examples/aml_example_Expressions_list.spy
87+
.. literalinclude:: /src/kernel/examples/aml_example_Expressions_list.spy
8888
:language: python
8989
* - **Objective**
90-
- .. literalinclude:: examples/kernel_example_Objectives_single.spy
90+
- .. literalinclude:: /src/kernel/examples/kernel_example_Objectives_single.spy
9191
:language: python
92-
.. literalinclude:: examples/kernel_example_Objectives_dict.spy
92+
.. literalinclude:: /src/kernel/examples/kernel_example_Objectives_dict.spy
9393
:language: python
94-
.. literalinclude:: examples/kernel_example_Objectives_list.spy
94+
.. literalinclude:: /src/kernel/examples/kernel_example_Objectives_list.spy
9595
:language: python
96-
- .. literalinclude:: examples/aml_example_Objectives_single.spy
96+
- .. literalinclude:: /src/kernel/examples/aml_example_Objectives_single.spy
9797
:language: python
98-
.. literalinclude:: examples/aml_example_Objectives_dict.spy
98+
.. literalinclude:: /src/kernel/examples/aml_example_Objectives_dict.spy
9999
:language: python
100-
.. literalinclude:: examples/aml_example_Objectives_list.spy
100+
.. literalinclude:: /src/kernel/examples/aml_example_Objectives_list.spy
101101
:language: python
102102
* - **SOS** [#sos_fn]_
103-
- .. literalinclude:: examples/kernel_example_SOS_single.spy
103+
- .. literalinclude:: /src/kernel/examples/kernel_example_SOS_single.spy
104104
:language: python
105-
.. literalinclude:: examples/kernel_example_SOS_dict.spy
105+
.. literalinclude:: /src/kernel/examples/kernel_example_SOS_dict.spy
106106
:language: python
107-
.. literalinclude:: examples/kernel_example_SOS_list.spy
107+
.. literalinclude:: /src/kernel/examples/kernel_example_SOS_list.spy
108108
:language: python
109-
- .. literalinclude:: examples/aml_example_SOS_single.spy
109+
- .. literalinclude:: /src/kernel/examples/aml_example_SOS_single.spy
110110
:language: python
111-
.. literalinclude:: examples/aml_example_SOS_dict.spy
111+
.. literalinclude:: /src/kernel/examples/aml_example_SOS_dict.spy
112112
:language: python
113-
.. literalinclude:: examples/aml_example_SOS_list.spy
113+
.. literalinclude:: /src/kernel/examples/aml_example_SOS_list.spy
114114
:language: python
115115
* - **Suffix**
116-
- .. literalinclude:: examples/kernel_example_Suffix_single.spy
116+
- .. literalinclude:: /src/kernel/examples/kernel_example_Suffix_single.spy
117117
:language: python
118-
.. literalinclude:: examples/kernel_example_Suffix_dict.spy
118+
.. literalinclude:: /src/kernel/examples/kernel_example_Suffix_dict.spy
119119
:language: python
120-
- .. literalinclude:: examples/aml_example_Suffix_single.spy
120+
- .. literalinclude:: /src/kernel/examples/aml_example_Suffix_single.spy
121121
:language: python
122-
.. literalinclude:: examples/aml_example_Suffix_dict.spy
122+
.. literalinclude:: /src/kernel/examples/aml_example_Suffix_dict.spy
123123
:language: python
124124
* - **Piecewise** [#pw_fn]_
125-
- .. literalinclude:: examples/kernel_example_Piecewise_1d.spy
125+
- .. literalinclude:: /src/kernel/examples/kernel_example_Piecewise_1d.spy
126126
:language: python
127-
- .. literalinclude:: examples/aml_example_Piecewise_1d.spy
127+
- .. literalinclude:: /src/kernel/examples/aml_example_Piecewise_1d.spy
128128
:language: python
129129
.. [#models_fn] :python:`pyomo.kernel` does not include an alternative to the :python:`AbstractModel` component from :python:`pyomo.environ`. All data necessary to build a model must be imported by the user.
130130
.. [#sets_fn] :python:`pyomo.kernel` does not include an alternative to the Pyomo :python:`Set` component from :python:`pyomo.environ`.

doc/OnlineDocs/src/kernel/examples.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#! /bin/bash
22

3-
for file in `ls ../../library_reference/kernel/examples/*.py | sort`; do python $file; done;
3+
dir=`dirname $0`
4+
for file in `ls ${dir}/examples/*.py | sort`; do python $file; done;

0 commit comments

Comments
 (0)