Octave - Ngspice interface

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave - Ngspice interface

CdeMills
Hello,

I have students developping simulations, and they needed to read into Octave results produced by Ngspice.

We used the set of file developped by Werner Hoch in 2005. Due to my students needs, I made two changes:
1) new function do_ngspice, which is a simple wrapper around ngspice call
2) spice_readfile: add the alility to read multiple "plots" present in the raw file. F.i., performing an AC sweep and requesting a ".OP" (operating point) computation lead to a file with two "plots"; one for the sweep, one for the DC components

Should I diffuse an update through ngspice maitainers, or should I create some package in octave-forge ?

Regards

Pascal
Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Kozma, Endre
Hello,

I met the similar problem last year, but I wanted full control over ngspice (wanted to control a buck-boost converter modeled in ngspice with a control algorithm developed in octave). I tried out some possibilities. They all were based on popen2, but because ngspice doesn't flush its outputs, thus I wasn't happy with that. Then I improved this popen2 method with using pseudo terminal. This latter worked quite well already, but parsing the received data was always a pain and the bloated octave code I had to write for that was far from what I liked. Fortunately as of release 26 ngspice delivers a shared dynamic library through which you can do practically anything with ngspice from octave. Probably you will have to compile it (I've never seen yet a binary package of the shared library), but hopefully it won't mean any problem for you. I built it without any problems in linux and cygwin. When the library is installed you can write the necessary oct-files (for interfacing octave and the library) to get and send data in an elegant and simple way. The library is independent from the ngspice application package, but it can do whatever the application can do except the user interface.
If you're interested in this I attached my oct-files as examples. Of course they are far from being perfect.

Just to wet your appetite here is an octave code snippet I can now deploy with this solution.

ngspice_init();
ngspice_command(["source simu.cir"; "tran 0.1us 6us uic"]);
[v6, v77] = ngspice_get_vector(["v(6)"; "v(77)"]);

You can see that the functions are quite general, so it might be be worth to create a nice octave package.

Regards,
Endre


On Wed, 2014-09-03 at 10:18 -0700, CdeMills wrote:
Hello,

I have students developping simulations, and they needed to read into Octave
results produced by Ngspice.

We used the set of file developped by Werner Hoch in 2005. Due to my
students needs, I made two changes:
1) new function do_ngspice, which is a simple wrapper around ngspice call
2) spice_readfile: add the alility to read multiple "plots" present in the
raw file. F.i., performing an AC sweep and requesting a ".OP" (operating
point) computation lead to a file with two "plots"; one for the sweep, one
for the DC components

Should I diffuse an update through ngspice maitainers, or should I create
some package in octave-forge ?

Regards

Pascal



--
View this message in context: http://octave.1599824.n4.nabble.com/Octave-Ngspice-interface-tp4666332.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.




ngspice_oct.tar.gz (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Richard Crozier
On 06/09/14 10:36, Kozma, Endre wrote:

> Hello,
>
> I met the similar problem last year, but I wanted full control over
> ngspice (wanted to control a buck-boost converter modeled in ngspice
>
>
> Regards,
> Endre
>
>


You might also be interested in Qucs,

https://sourceforge.net/projects/qucs/

for which there is an interface which allows you to dynamically extract
and set voltages etc. during a simulation. There are example scripts here:

https://sourceforge.net/p/qucs/git/ci/master/tree/examples/external_interface/m-interface/asynchronous_boost_converter_example.m

Note, however the interface requires classdef syntax only in development
octave.

Qucs also now has turnkey verilog-AMS support (you can write verilog-AMS
components and have them automatically converted to shared libraries and
called by the simulator engine).

Regards,
Richard


--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Nir Krakauer-2
Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Kozma, Endre
We're just about to create an Octave-Ngspice interface package. The idea would be to use the shared library of Ngspice. For building the package the user will definitely need the Ngspice-library installed. The problem is however that the library is fairly new, so there are no distros (Linux, Cygwin, MinGW, Solaris, BSDs, etc.) out there providing the necessary binary development package. This implies that
1. the user has to build and install the library with the corresponding header files into a specific path, or
2. the build framework of the Ngspice Octave-package shall attempt to download, build and install it (assuming that all the dependency libraries have already been previously installed). Building the library takes quite a few minutes on an average computer.

What is the preferred method?
Endre

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

marco atzeri-2
On 18/09/2014 17:57, Kozma, Endre wrote:

> We're just about to create an Octave-Ngspice interface package. The idea
> would be to use the shared library of Ngspice. For building the package
> the user will definitely need the Ngspice-library installed. The problem
> is however that the library is fairly new, so there are no distros
> (Linux, Cygwin, MinGW, Solaris, BSDs, etc.) out there providing the
> necessary binary development package. This implies that
> 1. the user has to build and install the library with the corresponding
> header files into a specific path, or
> 2. the build framework of the Ngspice Octave-package shall attempt to
> download, build and install it (assuming that all the dependency
> libraries have already been previously installed). Building the library
> takes quite a few minutes on an average computer.
>
> What is the preferred method?
> Endre
>

I could build the shared package for cygwin, but it seems that the code
is at list of version 26 is still immature.


Marco

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

al davis
In reply to this post by CdeMills
>>>>We're just about to create an Octave-Ngspice interface
>>>>package.

Why not gnucap??

http://gnucap.org
or
http://www.gnu.org/software/gnucap/


gnucap already is built as a linkable shared library, and
already has a plugin system.   The plugin system isn't just
device models.  It is a comprehensive system for extensions of
all kinds.

Also, for difficult circuits, it outperforms the others.

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Kozma, Endre
On Thu, 2014-09-18 at 15:52 -0400, al davis wrote:
>>>>We're just about to create an Octave-Ngspice interface
>>>>package. 

Why not gnucap??


If you're using Ngspice and Octave and you want an interface between them, then you just don't start developing an interface for gnucap. It would not make too much sense, I guess.
But pretend you are creating an Octave-interface for gnucap. How would you provide the gnucap library for different operating systems and different HW-platforms? And if the
library is already available, how do you know, where it is and where the corresponding header files are located (assume there is no .rc file for pkg-config yet)?

Endre
Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Kozma, Endre
In reply to this post by marco atzeri-2
On Thu, 2014-09-18 at 20:03 +0200, Marco Atzeri wrote:

I could build the shared package for cygwin, but it seems that the code 
is at list of version 26 is still immature.


Marco



Thanks, now it seems that the user will be forced to build/install the library by self.
The version 26 is still immature but once it will be the stable version, and the shared library is only provided by this version. On the other hand, as I see, the library and the interactive application are independent from each other. Thus e.g. I use the version 24 of the interactive Ngspice application (binary package installed from the official distro repository) and the library of version 26 built by me.

Endre
Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

marco atzeri-2
On 19/09/2014 14:41, Kozma, Endre wrote:

> On Thu, 2014-09-18 at 20:03 +0200, Marco Atzeri wrote:
>
>> I could build the shared package for cygwin, but it seems that the code
>> is at list of version 26 is still immature.
>>
>> Marco
>
> Thanks, now it seems that the user will be forced to build/install the
> library by self.
> The version 26 is still immature but once it will be the stable version,
> and the shared library is only provided by this version. On the other
> hand, as I see, the library and the interactive application are
> independent from each other. Thus e.g. I use the version 24 of the
> interactive Ngspice application (binary package installed from the
> official distro repository) and the library of version 26 built by me.
>
> Endre

for what I can see, the usual program version and the shared lib are
mutually exclusive in the ngspice build sequence.
That makes very complicated the distribution of a binary package
for both.
I raised the issue on ngspice development list

Regards
Marco


Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

Kozma, Endre
On Fri, 2014-09-19 at 14:52 +0200, Marco Atzeri wrote:

for what I can see, the usual program version and the shared lib are 
mutually exclusive in the ngspice build sequence.
That makes very complicated the distribution of a binary package
for both.
I raised the issue on ngspice development list

Regards
Marco


Yeah, you have to build and install them separately. It's not very elegant, but I'm glad that there is a library at least. Even if it's still a bit immature as you said.

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

al davis
In reply to this post by Kozma, Endre
On Friday 19 September 2014, Kozma, Endre wrote:
> If you're using Ngspice and Octave and you want an interface
> between them, then you just don't start developing an
> interface for gnucap. It would not make too much sense, I
> guess.

Ok I guess it's the same as if somebody said, perhaps in a
gnucap forum, "I want an interface to Scilab" and you responded
"why not Octave".

> But pretend you are creating an Octave-interface for gnucap.
> How would you provide the gnucap library for different
> operating systems and different HW-platforms? And if the
> library is already available, how do you know, where it is

If it's installed correctly "-lgnucap" should work.

> and where the corresponding header files are located

If it's installed correctly "#include <gnucap/xxxx.h> should
work.

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

A.R. Burgers
In reply to this post by marco atzeri-2
Marco Atzeri schreef op 2014-09-19 om 14:52:

> On 19/09/2014 14:41, Kozma, Endre wrote:
>> On Thu, 2014-09-18 at 20:03 +0200, Marco Atzeri wrote:
>>
>>> I could build the shared package for cygwin, but it seems that the code
>>> is at list of version 26 is still immature.
>>>
>>> Marco
>>
>> Thanks, now it seems that the user will be forced to build/install the
>> library by self.
>> The version 26 is still immature but once it will be the stable version,
>> and the shared library is only provided by this version. On the other
>> hand, as I see, the library and the interactive application are
>> independent from each other. Thus e.g. I use the version 24 of the
>> interactive Ngspice application (binary package installed from the
>> official distro repository) and the library of version 26 built by me.
>>
>> Endre
>
> for what I can see, the usual program version and the shared lib are mutually exclusive in the ngspice build sequence.
> That makes very complicated the distribution of a binary package
> for both.
> I raised the issue on ngspice development list
>
> Regards
> Marco
>

I built Endre Kozma's interface between octave and ngspice.
Both on cygwin and linux.
It works really well! Easy and fast retrieval of ngspice's simulation results.

I did indeed need to rebuild ngspice from the source package
with cygport, configuring --with-ngshared, then builds just fine,
creating the libngspice* libraries.
(and you need to include the *.cm files in the rebase procedure).

Hope the next version of cygwin's ngspice will have the shared option enabled.

Teun Burgers

Reply | Threaded
Open this post in threaded view
|

Re: Octave - Ngspice interface

marco atzeri-2
On 2/24/2015 11:08 PM, A.R. Burgers wrote:
> Marco Atzeri schreef op 2014-09-19 om 14:52:
>> On 19/09/2014 14:41, Kozma, Endre wrote:
>>> On Thu, 2014-09-18 at 20:03 +0200, Marco Atzeri wrote:

>>> Endre
>>
>> for what I can see, the usual program version and the shared lib are
>> mutually exclusive in the ngspice build sequence.
>> That makes very complicated the distribution of a binary package
>> for both.
>> I raised the issue on ngspice development list
>>
>> Regards
>> Marco
>>
>
> I built Endre Kozma's interface between octave and ngspice.
> Both on cygwin and linux.
> It works really well! Easy and fast retrieval of ngspice's simulation
> results.
>
> I did indeed need to rebuild ngspice from the source package
> with cygport, configuring --with-ngshared, then builds just fine,
> creating the libngspice* libraries.
> (and you need to include the *.cm files in the rebase procedure).
>
> Hope the next version of cygwin's ngspice will have the shared option
> enabled.

If I need to build 2 different packages, unlikely.
But I will look anyway.

Waiting from dev team for the status of version 27.

> Teun Burgers

Regards
Marco