automatic quantomatic? greased lightning!

9 views
Skip to first unread message

Ross Duncan

unread,
Nov 1, 2016, 1:39:53 PM11/1/16
to quant...@googlegroups.com
Hi quanto-lovers,

Is it possible to run quanto as a batch job? I wish to do the following:

i. load some graph into quanto (in the context of some project”)
ii. Smack it with some simproc (up to N steps)
iii. dump the resulting derivation in a file, and return the number of steps.

I want to do this to a potentially large number of files, so by hand is not a good option.

ideas?

-r

Aleks Kissinger

unread,
Nov 2, 2016, 5:43:43 AM11/2/16
to quant...@googlegroups.com
The best way to do this is with a python script. (cf. latest quanto build on "integration" branch).

I haven't written python hooks for calling custom simprocs yet,
​ but this is on my TODO list.​
​ On the other hand, n
aiive simplication (i.e. apply a list of rules until you can't) is supported.

Here's an example showing various hooks
​ in action​
. Note that, like simprocs, paths are relative to the root of the current project, and file extensions are omitted:

from quanto.util.Scripting import *

enc = load_graph('11-3/encoder')

rules = map(load_rule, [
  'pushers/gg', 'pushers/rr',
  'pushers/rgd', 'pushers/grd',
  'pushers/ggd', 'pushers/rrd',
  'pushers/ggu', 'pushers/rru'])

zinputs = ['b0', 'b3', 'b6', 'b7']
xinputs = ['b1', 'b5', 'b8', 'b9']

x = load_graph('pushers/X')
z = load_graph('pushers/Z')
for inp in zinputs:
  g = plug(enc, z, inp, 'b1')
  d = derivation(g)
  d.normalise(rules)
  d.save('11-3/stab/stab-Z-' + inp)
for inp in xinputs:
  g = plug(enc, x, inp, 'b1')
  d = derivation(g)
  d.normalise(rules)
  d.save('11-3/stab/stab-X-' + inp)




-r

--
You received this message because you are subscribed to the Google Groups "Quantomatic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic+unsubscribe@googlegroups.com.
To post to this group, send email to quant...@googlegroups.com.
Visit this group at https://groups.google.com/group/quantomatic.
For more options, visit https://groups.google.com/d/optout.

Ross Duncan

unread,
Nov 2, 2016, 6:48:26 AM11/2/16
to quant...@googlegroups.com
Hi Aleks,

Thanks for this! Do I understand right that I could simulate basic_simp using this feature? That would probably be adequate for my needs.

Related question: I have two students working on quanto based projects and they are going to need to implement tactics.
1. where is the best place to look for docs/examples on how to do this?
2. what things can the you do with the ML simproc interface that you can’t do with the python interface?
3. Does this “plug” method exist in the core? Can it be called from a simproc?

-r

On 2 Nov 2016, at 09:43, Aleks Kissinger <ale...@gmail.com> wrote:

> The best way to do this is with a python script. (cf. latest quanto build on "integration" branch).
>
> I haven't written python hooks for calling custom simprocs yet,​ but this is on my TODO list.​​ On the other hand, naiive simplication (i.e. apply a list of rules until you can't) is supported.
>
> Here's an example showing various hooks​ in action​. Note that, like simprocs, paths are relative to the root of the current project, and file extensions are omitted:
> To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic...@googlegroups.com.
> To post to this group, send email to quant...@googlegroups.com.
> Visit this group at https://groups.google.com/group/quantomatic.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Quantomatic" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic...@googlegroups.com.

Aleks Kissinger

unread,
Nov 2, 2016, 9:12:24 AM11/2/16
to quant...@googlegroups.com
1. the most complete example is rotate_simp, which uses most of the available features of simprocs. You can find all of the combinators by looking at the SIMP_UTIL signature in core/rewriting/simp_util.ML .

2. the most important thing simprocs can do beyond python is only applying rewrites that reduce a given graph metric. See REDUCE_METRIC and REDUCE_METRIC_TO combinators. A metric is just an ML function from graphs to ints (it's up to you to make sure it doesn't go negative!). These are generalised by REDUCE_WITH, which takes a pair of functions PRE and POST for giving pre- and post-conditions for performing a given rewrite step.

This could in principle by done in python, with something like:

while PRE_CONDITION(d.current_graph()):
  d.rewrite(rule)

Post-conditions can be implemented via backtracking, e.g.

d1 = d.copy()
d.rewrite(rule) // try something
if (!POST_CONDITION(d.current_graph())):
  d = d1
  // try something else

3. plugging happens on the front-end. It is just a wrapper for the scala function which does the same thing. This wouldn't make sense in a simproc, since simprocs should always give a (lazy) sequence of valid rewrite steps.

Note you can call any function in the scala frontend directly from python, since it all just gets compiled to JVM. So, the wrappers are really just meant to make scripting a bit easier, and more "pythonic".





> To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic+unsubscribe@googlegroups.com.

> To post to this group, send email to quant...@googlegroups.com.
> Visit this group at https://groups.google.com/group/quantomatic.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Quantomatic" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic+unsubscribe@googlegroups.com.

> To post to this group, send email to quant...@googlegroups.com.
> Visit this group at https://groups.google.com/group/quantomatic.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Quantomatic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quantomatic+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages