Authors
=======
Arpad Buermen

parts of the code contributed by 

Janez Puhan (HSPICE file interface)
Jernej Olensek (global optimization test problems)
Gregor Cijan (cost collector)


Credits 
=======
PyOpus uses code from the following packages
- FORTRAN test problems implemented by
  - Napsu Karmitsa
  - Ladislav Luksan and Jan Vlcek
  - Jorge More and Stefan Wild
- MADS test problems MDO and STYRENE implemented by Sebastien Le Digabel,
  Charles Audet, et. al. 

See src/*.zip and src/*.tar.gz for details on respective licenses. 


Installation from wheel files
=============================

Installation for Linux
----------------------
Tested under Debian 11 (Bullseye) amd64

1. Install Spice Opus (if you are not using some other supported simulator)
	Download from http://www.spiceopus.si
	Install to /usr/local

2. Install prerequisites (Debian packages)
	Become root
	Type
		apt-get install libstdc++6 libopenmpi-dev liblapack3 liblapack-dev libblas3 libblas-dev kicad python3.9 python3-pip python3-wheel python3-setuptools python3-numpy python3-scipy python3-matplotlib python3-greenlet python3-mpi4py python3-pyqt5 python3-lxml python3-pyqtgraph python3-cvxopt gfortran
		
	This installs packages
		libstdc++6
		libopenmpi-dev
		liblapack3
		liblapack-dev
		libblas3
		libblas-dev
		kicad (needed for schematic entry)
		python3.9
		python3-pip
		python3-wheel
		python3-setuptools
		python3-numpy
		python3-scipy
		python3-matplotlib
		python3-greenlet
		python3-mpi4py
		python3-pyqt5
		python3-lxml
		python3-pyqtgraph
		python3-cvxopt
		gfortran (for CUTEr support)
       
3. Install PyOPUS
	Get the PyOPUS .whl file for Linux from
		http://fides.fe.uni-lj.si/pyopus/download/0.10/PyOPUS-0.10-cp39-cp39-linux_x86_64.whl
	
	Now you can install PyOPUS. Become root and type 
		pip3 install PyOPUS-0.10-cp39-cp39-linux_x86_64.whl
	

Installation for Windows (quickstart)
-------------------------------------
Tested under Windows 10

1. Install KiCad (for schematic entry), tested with 6.0.4 x86_64
	Download from http://www.kicad.org/
    	Install

2. Install Spice Opus (if you are not using some other supported simulator)
	Download from http://www.spiceopus.si
    	Install to c:\SpiceOpus
	Reboot. 

3. Download PyOPUS 0.10 Windows quickstart from 
	http://fides.fe.uni-lj.si/pyopus/download/0.10/PyOPUS-0.10-quickstart-win_amd64.zip
	
   Unpack the zip file to c:\. 
   This will create folder c:\PyOPUS-0.10-quickstart-win_amd64
   
4. Install Python3
   In c:\PyOPUS-0.10-quickstart-win_amd64 run the Python3 installer
	python-3.10.4-amd64.exe
		Check "Add Python to path"
		Click "Customize installation"
		Check "PIP"
		Check "TCL/TK and Idle"
		Click "Next"
		Check "Install for all users"
		Check "Associate files with Python"
		Check "Add Python to environment variables"
		Check "Precompile standard library"
		Install to c:\Python310

5. Install Microsoft MPI
   In c:\PyOPUS-0.10-quickstart-win_amd64 run the MSMPI installer
	msmpisetup.exe

6. Install prerequisite wheel files and PyOPUS
   We suggest you use packages from Christoph Gohlke's site 
	http://www.lfd.uci.edu/~gohlke/pythonlibs/
	
   The required wheel files from that site are in c:\PyOPUS-0.10-quickstart-win_amd64
   along with the PyOPUS wheel file. Install them by running 
   	install.bat

7. Now you can delete
	c:\PyOPUS-0.10-quickstart-win_amd64
	
	
Installation for Windows (from your own package sources)
--------------------------------------------------------
Tested under Windows 10

1. Go through steps 1-3 of Installation for Windows (quickstart)

2. Download Python 3.10.x and install it to c:\Python310. 
   Make sure the Python interpreter is in the system path, i.e. add
   c:\Python310 and c:\Python310\Scripts to the PATH environmental variable. 

3. Download Microsoft MPI and install it. 

4. Install Python libraries
   wheel setuptools numpy scipy cvxopt matplotlib greenlet mpi4py lxml pyqt5 pyqtgraph
   
   Make sure mpi4py you are using is linked against the installed version of Microsoft MPI. 
   
5. Download PyOPUS from 
	http://fides.fe.uni-lj.si/pyopus/download/0.10/PyOPUS-0.10-cp310-cp310-win_amd64.whl
   
   Install it by opening the command prompt and typing
	pip install PyOPUS-0.10-cp310-cp310-win_amd64.whl


Configuring KiCad
=================
PyOPUS uses KiCad 5/6 as schematic editor. 
Start the schematic editor (eeschema). 
In KiCad 5 select Tools/Generate Netlist File in the menu. 
In KiCad 6 select File/Export/Netlist in the menu. 
Click "Add Plugin". Under "Name" enter::

  Spice Opus

Under "Netlist command" enter::

  python3 -m pyopus.netlister.kicad -i "%I" -o "%O"

For Windows the command for running the netlister is::

  <full path to pythonw.exe> -m pyopus.netlister.kicad -i "%I" -o "%O"

Click "OK". A tab will appear for generating Spice Opus netlists. 
You need to do this only once. KiCad will store your settings in its 
configuration. For Linux make sure python3 is in your path. Also make 
sure the PyOPUS installation folder is listed in the PYTHONPATH 
environmental variable if PyOPUS is not installed in the Python libraries 
folder. 

To make KiCad 5 behave in the same manner as KiCad 4 when placing symbols, 
select Preferences/General Options in the menu. Select the Editing tab. 
Uncheck:
  
  * Automatically place symbol fields
  * Allow field autoplace to change justification
  * Always allign autoplaced fields to the 50 mil grid

The pyopus symbol library for KiCad 5 is distributed with PyOPUS demos in 
demo/kicad/library as two files: pyopus.lib (symbol definitons) and 
pyopus.dcm (auxiliary data). 
For KiCad 6 there is only one file named pyopus.kicad_sym. 
To specify the location of the pyopus symbol library, select 
Preferences/Manage Symbol Libraries in the menu. In the Global Libraries 
tab click on Append Library. Fill the created entry with the following values:

  * Active: mark checkbox
  * Nickname: pyopus
  * Library Path: <absolute path to pyopus.lib for V5 or pyopus.kicad_sym for V6>
  * Plugin Type: Legacy for V5, KiCad for V6
  * Decription: PyOPUS symbol library

Leave the Options field empty. This procedure also needs to be done only once. 

To generate a Spice Opus netlist, select Tools/Generate Netlist File (KiCad 5)
or File/Export/Netlist (KiCad 6) in the menu. Choose the "Spice Opus" tab, and 
click on "Generate". A window with the generated netlist will pop up. In case 
of an error the window will show the error message. To disable the popup 
window and show it only in case of an error add the ``-n`` option to the 
Netlist command. 

Generating the netlist via the File/Export/Netlist menu entry in KiCad 6 is a 
bit awkward. An alternative approach is to set up the netlister as a bill of 
materials (BOM) generator script. You can achieve this in the following 
way. Click the BOM icon or select Tools/Generate BOM. Click the "+" icon to add 
a new BOM script. Select any .py file on your computer and click Open. Give a 
name to to the script (e.g. PyOPUS Netlister for KiCad). Change the command line 
running the generator into: 

  "/usr/bin/python3" -m pyopus.netlister.kicad -i "%I" -o "%O"
  
For Windows change it to

  "<full path to pythonw.exe>" -m pyopus.netlister.kicad -i "%I" -o "%O"
  
Now you can generate the netlist by clicking the BOM icon, choosing the 
"PyOpus Netlister for KiCad" BOM generator script and clicking Generate. 


Preparing PyOPUS for parallel processing with MPI 
=================================================
If you intend to run parallel processes on your local machine, there is 
nothing further to do. 

If you intend to run parallel processes on a computer farm and your home 
folder /home/<username> is nfs-mounted on all worker computers as 
/home/<username> there is nothing further to do. If this is not the case
see the documentation of pyopus.parallel.base and set the 
	PARALLEL_MIRRORED_STORAGE 

environmental variable on all computers participating in parallel 
processing. 

If you want your workers to use local copies of files (mirroring) for 
faster processing and you intend to use /tmp folder for storing the 
local copies, there is nothing further to do. If you want to store the 
local copies somewhere else see the documentation of pyopus.parallel.base 
and set the 
	PARALLEL_LOCAL_STORAGE 
	
environmentral variable on all computers participating in parallel 
processing. 

Under Windows you must start 
	
	smpd -d 3

in a command prompt on all hosts where you want to start MPI processes 
before starting any parallel runs. The ``-d 3`` option will produce debug 
output which will help you solve problems with your MPI setup. The smpd 
executable is a part of Microsoft MPI. 

Parallel processing on a computer farm was not tested under Windows. 
This is uncharted territory. Reports are welcome. 


Demos and documentation
=======================
Demos and documentation in html format are available as a .tar.gz archive at 
	http://fides.fe.uni-lj.si/pyopus/download/0.10/PyOPUS-0.10-doc-demo.tar.gz

Unpacked demos are available for browsing at
	http://fides.fe.uni-lj.si/pyopus/download/0.10/demo

Unpacked docs can be browsed at
	http://fides.fe.uni-lj.si/pyopus/download/0.10/docsrc/_build/html
	
	
Building PyOPUS from sources
============================
Download the source package from 
	http://fides.fe.uni-lj.si/pyopus/download/0.10/PyOPUS-0.10.tar.gz
and unpack it. 

Building for Linux (wheel, demos and documentation, and source)
---------------------------------------------------------------
Tested under Debian 11 (Bullseye) amd64

1. Install prerequisites for Linux PyOPUS installation

2. Install prerequisites for building. Type
	apt-get install gcc g++ libstdc++-10-dev make texlive texlive-latex-extra dvipng graphviz python3-wheel python3-dev python3-sphinx python3-sphinx-rtd-theme python3-setuptools

   This installs packages
	gcc
	g++
	libstdc++-10-dev
	make
	texlive
	texlive-latex-extra
	dvipng
	graphviz
	python3-dev
	python3-sphinx
	python3-sphinx-rtd-theme
	python3-wheel
	python3-setuptools
	
3. In the folder where PyOPUS sources are located type
	./pack
   
   The wheel file, demos and documentation, and the source package 
   will be placed under dist/

   
Building for Windows (wheel only)
---------------------------------
Tested under Windows 10

1. Install prerequisites for Windows PyOPUS installation

2. Install prerequisites for building
	Visual Studio 2019
	Python libraries (in command prompt)
		pip install setuptools
		pip install wheel
	pzthon -
3. Start VS 2019 x64 Native Tools Command Prompt, 
   go to the folder where PyOPUS sources are located, and type
	pack.bat
   
   The wheel file will be placed under dist/
   

Install PyOPUS for development (in source folders)
--------------------------------------------------
Enter the source folder (where pyopus/ subfolder is located). 
After building PyOPUS with 
	python3 setup.py build
	
type:
	pip3 install -e .
	
Note that this step is automatically performed by the pack (Linux) and 
pack.bat (Windows) scripts. To skip this step coment out the last part 
of the two scripts. 

