Skip to content

Commit

Permalink
NLWPY 0.0.1 #30
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Feb 16, 2024
1 parent a260eaa commit e3ffc3f
Show file tree
Hide file tree
Showing 13 changed files with 1,125 additions and 5 deletions.
5 changes: 3 additions & 2 deletions nl-writer2/examples/cpp/easyAPI_1_MIQP/nlsol_ex_easy_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ModelBuilder {
i+1, sol.x_[i], x_ref_[i]);
return false;
}
printf("MIQP 1: solution check ok.\n");
printf("MIQP 1: solution check ok, obj=%.17g.\n",
sol.obj_val_);
return true;
}

Expand Down Expand Up @@ -113,7 +114,7 @@ s.t. C2: x2_5 -x3_6 -x4_3 + x6_2 >= 10;
double obj_val_ref_ {-39.76};
};

/// Solver with given parameters
/// Solve with given parameters
bool SolveAndCheck(std::string solver, std::string sopts,
bool binary, std::string stub) {
ModelBuilder mdlbld;
Expand Down
9 changes: 6 additions & 3 deletions nl-writer2/include/mp/nl-solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ class NLHeader;
/// \endrst
class NLSolver {
public:
/// Construct.
NLSolver();

/// Construct.
///
/// @param put: pointer to NLUtils or a derived object
/// (optional).
NLSolver(mp::NLUtils* put=nullptr);
NLSolver(mp::NLUtils* put);

/// Destruct.
~NLSolver();
Expand Down Expand Up @@ -140,8 +143,8 @@ class NLSolver {
/// See LoadModel(), Solve(), ReadSolution()
/// for details.
NLSolution Solve(const NLModel& mdl,
const std::string& solver,
const std::string& solver_opts) {
const std::string& solver,
const std::string& solver_opts) {
NLSolution sol;
if (LoadModel(mdl)
&& Solve(solver, solver_opts)) {
Expand Down
58 changes: 58 additions & 0 deletions nl-writer2/nlwpy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
nlwpy
==============

An example project built with [pybind11](/~https://github.com/pybind/pybind11).
This requires Python 3.7+; for older versions of Python, check the commit
history.

Installation
------------

- clone this repository
- `pip install ./nlwpy [--prefix=.]`

CI Examples
-----------

There are examples for CI in `.github/workflows`. A simple way to produces
binary "wheels" for all platforms is illustrated in the "wheels.yml" file,
using [`cibuildwheel`][]. You can also see a basic recipe for building and
testing in `pip.yml`, and `conda.yml` has an example of a conda recipe build.


Building the documentation
--------------------------

Documentation for the example project is generated using Sphinx. Sphinx has the
ability to automatically inspect the signatures and documentation strings in
the extension module to generate beautiful documentation in a variety formats.
The following command generates HTML-based reference documentation; for other
formats please refer to the Sphinx manual:

- `cd python_example/docs`
- `make html`

License
-------

pybind11 is provided under a BSD-style license that can be found in the LICENSE
file. By using, distributing, or contributing to this project, you agree to the
terms and conditions of this license.

Test call
---------

Inline:

```python
import nlwpy as m
m.add(1, 2)
```

Use tests:

```bash
[PYTHONPATH=./<installation path++>] python test.py
```

[`cibuildwheel`]: https://cibuildwheel.readthedocs.io
35 changes: 35 additions & 0 deletions nl-writer2/nlwpy/conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package:
name: python_example
version: 0.0.1

source:
path: ..

build:
number: 0
script: {{ PYTHON }} -m pip install . -vvv

requirements:
build:
- {{ compiler('cxx') }}

host:
- python
- pip
- pybind11 >=2.10.0

run:
- python


test:
imports:
- python_example
source_files:
- tests
commands:
- python tests/test.py

about:
summary: An example project built with pybind11.
license_file: LICENSE
Loading

0 comments on commit e3ffc3f

Please sign in to comment.