Search Techniques
VerifAI provides several techniques for exploring the semantic search space for verification, testing, and synthesis. These are largely based on sampling and optimization methods. In the tool, we refer to all of these as “samplers”.
There are three active samplers (i.e. cross entropy, simulated annealing, and bayesian optimization samplers) and two passive samplers (i.e. random and halton samplers) supported. The details of their implementation can be found in verifai/samplers directory.
How to add a new sampler?
First, add your python script of your sampler in verifai/samplers directory along with other sampler scripts. Second, add an API to call your sampler in verifai/samplers/feature_sampler.py
Sampling from a Scenic program
Defining the semantic feature space using a Scenic program (instead of the Feature APIs in VerifAI) requires the use of a special sampler, ScenicSampler.
- class ScenicSampler(scenario, maxIterations=None, ignoredProperties=None)[source]
Samples from the induced distribution of a Scenic scenario.
Created using the
fromScenarioandfromScenicCodeclass methods.See Scene Generation in the Scenic documentation for details of how Scenic’s sampler works. Note that VerifAI’s other samplers can be used from within a Scenic scenario by defining external parameters.
- classmethod fromScenario(path, maxIterations=None, maxSteps=None, ignoredProperties=None, **kwargs)[source]
Create a sampler corresponding to a Scenic program.
The only required argument is
path, andmaxIterationsmay be useful if your scenario requires a very large number of rejection sampling iterations. Seescenic.scenarioFromFilefor details on optional keyword arguments used to customize compilation of the Scenic file.- Parameters:
path (str) – path to a Scenic file.
maxIterations (int) – maximum number of rejection sampling iterations (default 2000).
ignoredProperties – properties of Scenic objects to not include in generated samples (see
defaultIgnoredPropertiesfor the default).kwargs – additional keyword arguments passed to
scenic.scenarioFromFile; e.g.paramsto override global parameters ormodelto set the world model.
- classmethod fromScenicCode(code, maxIterations=None, maxSteps=None, ignoredProperties=None, **kwargs)[source]
As above, but given a Scenic program as a string.
- pointForScene(scene)[source]
Convert a sampled Scenic
Sceneto a point in our feature space.The
FeatureSpaceused by this sampler consists of 2 features:objects, which is aStructconsisting of attributesobject0,object1, etc. with the properties of the corresponding objects in the Scenic program. The names of these attributes may change in a future version of VerifAI: use thenameForObjectfunction to generate them.params, which is aStructstoring the values of the global parameters of the Scenic program (useparamDictForSampleto extract them).
- static nameForObject(i)[source]
Name used in the
FeatureSpacefor the Scenic object with index i.That is, if
sceneis aScene, the objectscene.objects[i].
- paramDictForSample(sample)[source]
Recover the dict of global parameters from a
ScenicSamplersample.