Top Up Prev Next Bottom Contents Index Search

3.12 Some hints on advanced uses of ptcl with pigi


Although we have not had time to pursue it aggressively in this release, flexible control of Ptolemy simulations (e.g. executing a simulation many times with different parameter settings) is now possible. This can be done by using ptcl and pigi together.

Warning: This mechanism is still under development, so please note that what is described in this section is likely to change.

3.12.1 Ptcl as a simulation control language for pigi

If you start pigi with the -console option, then a console window will appear that will accept ptcl commands. To experiment with this, open the sinMod demo in the SDF basic demo palette, and execute the pigi command compile-facet (in the Exec submenu). This command reads the oct facet from disk, and constructs the Ptolemy data structures to represent it in memory. In your console window, you should see the prompt:

pigi>
Note what happens if you ask for the name of the current universe:

pigi> curuniverse
sinMod
pigi>
By compiling the facet, you have created a universe called sinMod, and made it the current universe. If you just started pigi, then this is one of only two universes in existence:

pigi> univlist
main sinMod
pigi>
The universe main is the default, empty universe that Ptolemy starts with. To verify the contents of the sinMod universe, use the print command:

pigi> print
GALAXY: sinMod
Descriptor: An interpreted galaxy
Contained blocks: singen2 modulator1 XMgraph.input=11
pigi> 
You can execute this universe from the console window:

pigi> run 400
pigi> wrapup
Notice that you will not see any output until you invoke the wrapup command, since the XMgraph star creates the output plot in its wrapup method.

So far, you have not done anything you could not have done more directly using pigi. However, you can change the value of parameters from ptcl. To do this, you must first determine the name of the instance of the star or galaxy with the parameter you want to control. Place the mouse over the singen icon in the sinMod galaxy, and issue the pigi show-name (`n') command. Most likely, the name will be singen2, although it could be different on successive runs. This is an instance name generated automatically by pigi. Notice that it is the name shown by the print command above. Also, use the edit-params (`e') command over the singen icon to determine that singen2 has a parameter named frequency with value PI/100. Now try the following commands:

pigi> setstate singen2 frequency PI/50
pigi> run 400
pigi> wrapup
Notice that the frequency of the modulating sinusoid is now twice as high as before.

Much more interestingly, you can now construct a series of runs using Tcl as a scripting language:

pigi> foreach i {0.25 0.5 0.75 1 1.25 1.5} {
pigi? setstate singen2 frequency $i*PI/100
pigi? setstate XMgraph.input=11 title \ 
pigi? "message frequency = [expr 0.01*$i]*PI"
pigi? run 400
pigi? wrapup
pigi? }
pigi>
This will invoke six runs, each with a different frequency parameter for the singen galaxy singen2. The foreach command is a standard Tcl command. Notice that in the third and fourth lines, we have also set the title parameter of the XMgraph star. This is advisable because otherwise it might be very difficult to tell which result corresponded to which run. Notice that the name of the XMgraph instance is "XMgraph.input=11". It is a more complicated name because the icon is specialized to have only a single input port.

Using the full power of the Tcl language, the above mechanism can become extremely powerful. To use its full power, however, you will most likely want to construct your Tcl scripts in files. These files can even include the universe definition, as explained below, so you can create scripts that can be run under ptcl only, independent of pigi.

3.12.2 The pigi log file pigiLog.pt

In each pigi session, a log file named pigiLog.pt is generated in the user's home directory. Every time an oct facet that represents a Ptolemy galaxy or universe is compiled, for example when running a simulation, the equivalent ptcl commands building the galaxy or universe are logged in pigiLog.pt. For example, if you followed the above procedure, opening the sinMod demo and issuing the compile-facet command, your pigiLog.pt file will contain something like the following:

reset
domain SDF
defgalaxy singen {
domain SDF
newstate sample_rate FLOAT "2*PI"
newstate frequency FLOAT "PI/50"
newstate phase_in_radians float 0.0
star Ramp1 Ramp
setstate Ramp1 step "2*PI*frequency/sample_rate"
setstate Ramp1 value phase_in_radians
star Sin1 Sin
connect Ramp1 output Sin1 input
alias out Sin1 output
}
defgalaxy modulator {
domain SDF
newstate freq FLOAT 0.062832
star "Mpy.input=21" Mpy
numports "Mpy.input=21" input 2
star singen1 singen
setstate singen1 sample_rate "2*PI"
setstate singen1 frequency freq
setstate singen1 phase_in_radians 0.0
alias in "Mpy.input=21" "input#1"
alias out "Mpy.input=21" output
connect singen1 out "Mpy.input=21" "input#2"
}
newuniverse sinMod SDF
target default-SDF
	targetparam logFile ""
targetparam loopScheduler NO
targetparam schedulePeriod 10000.0
star singen2 singen
setstate singen2 sample_rate "2*PI"
setstate singen2 frequency "PI/100"
setstate singen2 phase_in_radians 0.0
star modulator1 modulator
setstate modulator freq "0.2*PI"
star "XMgraph.input=11" XMgraph
numports "XMgraph.input=11" input 1
setstate "XMgraph.input=11" title "A modulator demo"
setstate "XMgraph.input=11" saveFile ""
setstate "XMgraph.input=11" options "=800x400+0+0 -0 x"
setstate "XMgraph.input=11" ignore 0
setstate "XMgraph.input=11" xUnits 1.0
setstate "XMgraph.input=11" xInit 0.0
connect singen2 out modulator1 in
connect modulator1 out "XMgraph.input=11" "input#1"
This is a ptcl definition of a universe that is equivalent to the oct facet. In normal usage, you may need to edit this file considerably to extract the portions you need, because all the galaxies and universes compiled in a pigi session are logged in the same log file. Also, as of this writing, the file does not necessarily get flushed after your compile-facet command completes, so the last few lines may not appear until more lines are written to the file, or you exit pigi.

Note that pigi compiles the sub-galaxies recursively before compiling the top-level universe. Therefore, the ptcl definitions are generated and logged in this recursive order. For instance, in the pigiLog.pt shown above, ptcl definitions of the singen and modulator galaxies appear before that of the sinMod universe. Also, if a galaxy has been compiled before, and thus is on the knownlist, its ptcl definition will not be generated and logged again when it is used in another universe.

One use of the ptcl definitions obtained from pigiLog.pt is to submit bug reports. It is the best way to describe in ASCII text the Ptolemy universe that causes problems.

3.12.3 Using pigiLog.pt to build scripts

If you restart pigi, run the sinMod demo in the SDF basic demo palette once, then quit pigi, then your pigiLog.pt file will be as above. Make a copy of pigiLog.pt and name it, say, sinMod.pl.

To run this simulation with different message waveform frequencies, you may do the following in ptcl, analogous to the above commands in pigi:

# build the sinMod universe
source sinMod.pl
foreach i {0.25 0.5 0.75 1 1.25 1.5} {
	# set parameter values
	setstate singen2 frequency $i*PI/100
	setstate XMgraph.input=11 title \ 
	"message frequency = [expr 0.01*$i]*PI"
	# execute it
	run 400
	wrapup
}
The combination of ptcl and pigi is very powerful. The above are just some hints on how they can be used together.

3.12.4 oct2ptcl

Kennard White's program oct2ptcl can be used to convert Ptolemy facets to ptcl code. Oct2ptcl is not part of the default distribution, and it is not built automatically. You can find the oct2ptcl sources in the other.src tar file in ptolemy/src/octtools/tkoct/oct2ptcl. oct2ptcl is not formally part of Ptolemy, but some developers may find it useful.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.