Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
29 changes: 13 additions & 16 deletions docs/codegen/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,28 @@ Additional codegen options are shown in the following table
|| :code:`printing_enable` || Enable printing || :code:`False` (default) |
|| || || :code:`True` |
+------------------------------+---------------------------------------------------+------------------------------+
|| Enable profiling || Enable profiling || :code:`False` (default) |
|| :code:`profiling_enable` || Enable profiling || :code:`False` (default) |
|| || || :code:`True` |
+------------------------------+---------------------------------------------------+------------------------------+
|| Enable interrupts || Enable interrupts || :code:`False` (default) |
|| :code:`interrupt_enable` || Enable interrupts || :code:`False` (default) |
|| || || :code:`True` |
+------------------------------+---------------------------------------------------+------------------------------+
|| :code:`include_codegen_src` || Include codegen source code || :code:`True` (default) |
|| || || :code:`False` |
|| :code:`include_codegen_src` || Include codegen source code (this includes || :code:`True` (default) |
|| || headers/sources/Makefile in the output folder, || :code:`False` |
|| || creating a self-contained compilable folder. || |
+------------------------------+---------------------------------------------------+------------------------------+
|| :code:`prefix` || Prefix to add || :code:`''` (default) |
|| || || string |
|| :code:`prefix` || Prefix for filenames and C variables, || :code:`''` (default) |
|| || useful if generating multiple problems. || string |
+------------------------------+---------------------------------------------------+------------------------------+
|| :code:`compile` || Compile the code || :code:`False` (default) |
|| || || :code:`True` |
|| :code:`compile` || Compile the above python extension into an || :code:`False` (default) |
|| || importable module, allowing "import emosqp" || :code:`True` |
+------------------------------+---------------------------------------------------+------------------------------+

The options are passed using named arguments, e.g.,

.. code:: python

m.codegen('code', parameters='matrices', extension_name='emosqp')

If the :code:`project_type` argument is not passed or is set to :code:`''`,
then no build files are generated.

m.codegen('code', parameters='matrices', extension_name='myosqpext')


Extension module API
Expand All @@ -68,9 +65,9 @@ Once the code is generated, you can import a light python wrapper with

.. code:: python

import emosqp
import myosqpext

where :code:`emosqp` is the extension name given in the previous section. The module imports the following functions
where :code:`myosqpext` is the extension name given in the previous section. The module imports the following functions

.. py:function:: solve()
:noindex:
Expand Down Expand Up @@ -171,4 +168,4 @@ You can update all the nonzero entries in matrix :math:`A` by running

.. code:: python

emosqp.update_A(Ax_new, None, 0);
myosqpext.update_A(Ax_new, None, 0);
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# General information about the project.
project = 'OSQP'
copyright = '2021, Bartolomeo Stellato, Goran Banjac'
copyright = '2025, OSQP Developer Team'
author = 'Bartolomeo Stellato, Goran Banjac'

# The version info for the project you're documenting, acts as replacement for
Expand Down
98 changes: 2 additions & 96 deletions docs/contributing/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,102 +14,8 @@ check what algebra backends we have successfully built.

$ python -c "from osqp import algebras_available; print(algebras_available())"

Wrappers for ``builtin`` algebra
--------------------------------

Building wrappers for the ``builtin`` algebra demonstrates some of the basic steps
you would need to take for all algebra backends.

.. code-block:: bash

$ conda create --name osqp_build python=3.9
$ conda activate osqp_build

# "build" is the python package that is capable of generating binary "wheels"
# there are other ways of doing this but this way is the most standards compliant
$ pip install build

$ git clone [email protected]:osqp/osqp-python.git
$ cd osqp-python/

# Build the python wheels for "builtin" algebra
$ python -m build .

# Built artifacts are in the "dist" folder, we can "pip install" any of these files
# installing the wheel entails no (further) compilation so its fastest
$ tree dist
dist
β”œβ”€β”€ osqp-1.0.0b1-cp39-cp39-linux_x86_64.whl <- compiled wheel
└── osqp-1.0.0b1.tar.gz <- source gz

$ pip install dist/osqp-1.0.0b1-cp39-cp39-linux_x86_64.whl

$ python -c "from osqp import algebras_available; print(algebras_available())"
['builtin']

Wrappers for ``mkl`` algebra
----------------------------

For building Python wrappers for the ``MKL`` algebra backend, you need to have the `Intel OneAPI <https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html#base-kit>`_.
library installed and accessible for your platform.

Once installed, set the environment variable ``MKL_ROOT`` to the path of the installed toolkit. For example:

.. code-block:: bash

$ export MKL_ROOT=/opt/intel/oneapi/mkl/latest

The process of building the ``MKL`` OSQP wrappers is the same as above, except that the environment variable
``OSQP_ALGEBRA_BACKEND`` set to ``mkl`` tells the build process that we wish to build MKL wrappers.

.. code-block:: bash

$ export OSQP_ALGEBRA_BACKEND=mkl

$ python -m build .

$ tree dist
dist
β”œβ”€β”€ osqp-1.0.0b1-cp39-cp39-linux_x86_64.whl
β”œβ”€β”€ osqp-1.0.0b1.tar.gz
β”œβ”€β”€ osqp_mkl-1.0.0b1-cp39-cp39-linux_x86_64.whl
└── osqp_mkl-1.0.0b1.tar.gz

$ pip install dist/osqp_mkl-1.0.0b1-cp39-cp39-linux_x86_64.whl
$ python -c "from osqp import algebras_available; print(algebras_available())"
['mkl', 'builtin']

Wrappers for ``cuda`` algebra
-----------------------------

For building Python wrappers for the ``CUDA`` algebra backend, you need to have the `CUDA Toolkit <https://developer.nvidia.com/cuda-toolkit-archive>`_.
installed and accessible for your platform. The build process has been tested out for CUDA Toolkit versions 11.2 through 11.7.

If you install the CUDA Toolkit using the default paths and options (which makes the toolkit available at ``/usr/local/cuda`` for \*nix platforms),
there is no need for any further configuration.

The process of building the ``CUDA`` OSQP wrappers is the same as above, except that the environment variable
``OSQP_ALGEBRA_BACKEND`` set to ``cuda`` tells the build process that we wish to build CUDA wrappers.

.. code-block:: bash

$ export OSQP_ALGEBRA_BACKEND=cuda

$ python -m build .

$ tree dist
dist
β”œβ”€β”€ osqp-1.0.0b1-cp39-cp39-linux_x86_64.whl
β”œβ”€β”€ osqp-1.0.0b1.tar.gz
β”œβ”€β”€ osqp_cuda-1.0.0b1-cp39-cp39-linux_x86_64.whl
β”œβ”€β”€ osqp_cuda-1.0.0b1.tar.gz
β”œβ”€β”€ osqp_mkl-1.0.0b1-cp39-cp39-linux_x86_64.whl
└── osqp_mkl-1.0.0b1.tar.gz

$ pip install dist/osqp_cuda-1.0.0b1-cp39-cp39-linux_x86_64.whl
$ python -c "from osqp import algebras_available; print(algebras_available())"
['cuda', 'mkl', 'builtin']

See :ref:`Building alternative algebra backends <python_build_algebras>` on how to build and test
different OSQP algebra backends.

Building wrappers against an experimental branch of OSQP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
35 changes: 35 additions & 0 deletions docs/examples/setup-and-solve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,38 @@ C

return (int)exitflag;
};



Rust
----

.. code:: rust

use osqp::{CscMatrix, Problem, Settings};

fn main() {
// Define problem data
let P = &[[4.0, 1.0],
[1.0, 2.0]];
let q = &[1.0, 1.0];
let A = &[[1.0, 1.0],
[1.0, 0.0],
[0.0, 1.0]];
let l = &[1.0, 0.0, 0.0];
let u = &[1.0, 0.7, 0.7];

// Extract the upper triangular elements of `P`
let P = CscMatrix::from(P).into_upper_tri();

let settings = Settings::default();

// Create an OSQP problem
let mut prob = Problem::new(P, q, A, l, u, &settings).expect("failed to setup problem");

// Solve problem
let result = prob.solve();

// Print the solution
println!("{:?}", result.x().expect("failed to solve problem"));
}
45 changes: 45 additions & 0 deletions docs/examples/update-matrices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,48 @@ C

return (int)exitflag;
};



Rust
----

.. code:: rust

use osqp::{CscMatrix, Problem, Settings};

fn main() {
// Define problem data
let P = &[[4.0, 1.0],
[1.0, 2.0]];
let q = &[1.0, 1.0];
let A = &[[1.0, 1.0],
[1.0, 0.0],
[0.0, 1.0]];
let l = &[1.0, 0.0, 0.0];
let u = &[1.0, 0.7, 0.7];

// Extract the upper triangular elements of `P`
let P = CscMatrix::from(P).into_upper_tri();

let settings = Settings::default();

// Create an OSQP problem
let mut prob = Problem::new(P, q, A, l, u, &settings).expect("failed to setup problem");

// Solve problem
let result = prob.solve();

// Update P/A without changing their sparsity structure
// NB: Update only upper triangular part of P
prob.update_P_A(
&CscMatrix::from(&[[5.0, 1.5], [1.5, 1.0]]).into_upper_tri(),
&[[1.2, 1.1], [1.5, 0.0], [0.0, 0.8]],
);

// Solve updated problem
let result = prob.solve();

// Print the solution
println!("{:?}", result.x().expect("failed to solve problem"));
}
42 changes: 42 additions & 0 deletions docs/examples/update-vectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,45 @@ C

return (int)exitflag;
};



Rust
----

.. code:: rust

use osqp::{CscMatrix, Problem, Settings};

fn main() {
// Define problem data
let P = &[[4.0, 1.0],
[1.0, 2.0]];
let q = &[1.0, 1.0];
let A = &[[1.0, 1.0],
[1.0, 0.0],
[0.0, 1.0]];
let l = &[1.0, 0.0, 0.0];
let u = &[1.0, 0.7, 0.7];

// Extract the upper triangular elements of `P`
let P = CscMatrix::from(P).into_upper_tri();

let settings = Settings::default();

// Create an OSQP problem
let mut prob = Problem::new(P, q, A, l, u, &settings).expect("failed to setup problem");

// Solve problem
let result = prob.solve();

// Update problem
prob.update_lin_cost(&[2.0, 3.0]);
prob.update_bounds(&[2.0, -1.0, -1.0], &[2.0, 2.5, 2.5]);

// Solve updated problem
let result = prob.solve();

// Print the solution
println!("{:?}", result.x().expect("failed to solve problem"));
}
12 changes: 11 additions & 1 deletion docs/get_started/C.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Binaries
Precompiled platform-dependent shared and static libraries are available on `GitHub <https://github.com/osqp/osqp/releases>`__.
We here assume that the user uncompressed each archive to :code:`OSQP_FOLDER`.

Each archive contains static :code:`OSQP_FOLDER/lib/libosqp.a` and shared :code:`OSQP_FOLDER/lib/libosqp.ext` libraries to be used to interface OSQP to any C/C++ software.
Each archive contains static :code:`OSQP_FOLDER/lib/libosqpstatic.a` and shared :code:`OSQP_FOLDER/lib/libosqp.ext` libraries to be used to interface OSQP to any C/C++ software.
The extension :code:`.ext` is platform dependent and is :code:`.so` for Linux, :code:`.dylib` for Mac and :code:`.dll` for Windows.
The required include files can be found in :code:`OSQP_FOLDER/include`.

Expand Down Expand Up @@ -40,4 +40,14 @@ If you compiled OSQP from sources and followed the CMake installation instructio
# Link the OSQP static library
target_link_libraries(yourTarget PRIVATE osqp::osqpstatic)

You will need to help CMake out by specifying the path to the folder where you installed the OSQP library, for example:

.. code:: bash

cmake --build . -Dosqp_ROOT=myfolder

You may or may not need to link your target to the standard math library in your :code:`CMakeLists.txt` file:

.. code::

target_link_libraries(yourTarget PRIVATE m)
2 changes: 1 addition & 1 deletion docs/get_started/linear_system_solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ However, it becomes not really efficient for large scale problems since it is no


oneMKL Pardiso
-----------
--------------
`oneMKL Pardiso <https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2023-0/onemkl-pardiso-parallel-direct-sparse-solver-iface.html>`_ is an efficient multi-threaded linear system solver that works well for large scale problems part of the Intel Math Kernel Library.
Intel offers `free licenses <https://www.intel.com/content/www/us/en/developer/articles/tool/onemkl-license-faq.html>`_ for oneMKL for most non-commercial applications.

Expand Down
12 changes: 3 additions & 9 deletions docs/get_started/matlab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ After you install both, check that your compiler is selected by executing
setenv('MW_MINGW64_LOC', 'C:\TDM-GCC-64')


where :code:`C:\TDM-GCC-64` is the installation folder for TDM-GCC.
where :code:`C:\\TDM-GCC-64` is the installation folder for TDM-GCC.

You can now build the interface by running inside Matlab

.. code:: matlab

!git clone --recurse-submodules https://github.com/osqp/osqp-matlab
cd osqp-matlab
make_osqp
osqp.build('osqp_mex')


Then you can add the interface to the search path by executing from the same directory

.. code:: matlab

addpath(pwd)
savepath
You are now ready to start using the Matlab interface.
Loading
Loading