ParametricInversion.jl
Parametric Inversion is a library for inverting Julia programs.
Quick Start
using ParametricInversion
f(x, y, z) = x + y * z
x_, y_, z_ = rand(3)
output = f(x_, y_, z_)
params = rand(2)
(x__, y__, z__) = invertinvoke(f, Tuple{Float64, Float64, Float64}, output, params)
f(x__, y__, z__)
Index
ParametricInversion.ParametricInversion
ParametricInversion.Loc
ParametricInversion.PIConstant
ParametricInversion.Places
ParametricInversion.add!
ParametricInversion.branchpreds
ParametricInversion.branchvars
ParametricInversion.choose
ParametricInversion.cycle
ParametricInversion.duplify!
ParametricInversion.enumplaces
ParametricInversion.fargs
ParametricInversion.head
ParametricInversion.incomingbranches
ParametricInversion.inverseparameters
ParametricInversion.invert
ParametricInversion.invert!
ParametricInversion.invertci
ParametricInversion.invertinvoke
ParametricInversion.invertir
ParametricInversion.knownvars
ParametricInversion.locallyundefinedvars
ParametricInversion.nused
ParametricInversion.nused
ParametricInversion.passvars!
ParametricInversion.producedvars
ParametricInversion.reversestatements!
ParametricInversion.stmtargtypes
ParametricInversion.stmts
ParametricInversion.usedvars
ParametricInversion.varreplace!
ParametricInversion.varstatements
ParametricInversion.vartypes
ParametricInversion.ParametricInversion
— ModuleJulia in reverse: Parametric Inversion in pure Julia
ParametricInversion.Loc
— TypeLocation in trace
ParametricInversion.PIConstant
— TypeConstant
ParametricInversion.Places
— TypePlaces refers to a subset of the axes (aka dimension, column, attributes) of relation
ParametricInversion.add!
— Methodadd v
to vm[k]
ParametricInversion.branchpreds
— MethodAll
ParametricInversion.branchvars
— MethodVars that are used in branching in block b
ParametricInversion.choose
— Functionchoose(ctx, loc, f, types, target, known. θ)
Parametrically choose a value for variables in relation defined by method f(::types..)
, given information about other values in relation.
Arguments
f(::types...)
- method to choose fromloc
- Locationtarget
- which axis we wish to choose ontogiven
- what is given/known about values of the relation (e.g. value of input)θ
- Parameter values which determine which element to choose
ParametricInversion.cycle
— Methodcycle(f, args...)
yields xs_
such f(xs_...) == f(args...)
`
ParametricInversion.duplify!
— MethodEnsure there is single usage of a particular variable
ParametricInversion.enumplaces
— MethodFor statement of the form v1 = f(v2, v3, ..., vn)
produces [v1, v2, ..., vn]
ParametricInversion.fargs
— MethodArguments of a statement
ParametricInversion.head
— MethodHead of expression defined by statement
ParametricInversion.incomingbranches
— MethodWhat branchblocks are incoming into block b
ParametricInversion.inverseparameters
— FunctionParameters that can be used to invert to x
from y
parameters(f, types, args...)
Produces parameters θ
such that:
inverseparameters(f, types, f(args...), θ) == args
These parameters can be used for learning.
ParametricInversion.invert!
— Methodinvert block b
, store result in invb
, assume v ∈ knownvars
is known
ParametricInversion.invert
— Methodir::IR
that computes inverse inverse of ir
ParametricInversion.invertci
— MethodProduce inverse ::CodeInfo
ParametricInversion.invertinvoke
— Methodinvertinvoke(f, t::Type{<:Tuple}, z, θ)
Parametric inverse application of method f(::t...)
to args
with parameters θ
Inputs:
f
- function to invert t
- Tuple of types which determines method of f
to invert z
- Input to inverse method θ
- Parameter values
Returns
(a, b, c, ...)
- tuple of values
f(x, y, z) = x * y + z
x, y, z = invertinvoke(f, Tuple{Float64, Float64, Float64}, 2.3, rand(3))
@assert f(x, y, z) == 2.3
ParametricInversion.invertir
— Methodinvertir(f, t::Type{T})
Produce inverse ast for method f(::T)
ParametricInversion.knownvars
— MethodWhen entering block
at branchpoint brid
, which variables are known?
ParametricInversion.locallyundefinedvars
— MethodVariables that are used in block b
but neither defined in b
nor inputs to b
ParametricInversion.nused
— MethodNumber of times var
is used in block
ParametricInversion.nused
— MethodNum times v
is used in smt
ParametricInversion.passvars!
— Methodpassvars!(ir)
Removes implicit use of variable. Updates ir
such that if a block uses some variable v
then v
is an input to that block.
ParametricInversion.producedvars
— MethodVariables that are produced by b
: inputs or lhs of statements
ParametricInversion.reversestatements!
— MethodUndo each operation statement %a = f(%x, %y, %z)
in b
, add to invb
ParametricInversion.stmtargtypes
— MethodArgument types of statement stmt
according to vartypes vtypes
ParametricInversion.stmts
— Methodvars used in statements of b
ParametricInversion.usedvars
— Methodvars used in some form by block b
ParametricInversion.varreplace!
— MethodRepalce all occurances of x
with y
variable v1
with variable v2
in block b
ParametricInversion.varstatements
— MethodEach statement of block b
and associated Variable
ParametricInversion.vartypes
— MethodMapping from variables (including arguments) to inferred types