Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
20b48809
Commit
20b48809
authored
13 years ago
by
Régis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
improving random testing and terminating actors at main exit
parent
969ec83b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/purescala/ParallelSolver.scala
+3
-2
3 additions, 2 deletions
src/purescala/ParallelSolver.scala
src/purescala/RandomSolver.scala
+36
-37
36 additions, 37 deletions
src/purescala/RandomSolver.scala
with
39 additions
and
39 deletions
src/purescala/ParallelSolver.scala
+
3
−
2
View file @
20b48809
...
...
@@ -12,6 +12,7 @@ import TypeTrees._
import
Evaluator._
import
scala.actors.Actor
import
scala.actors.DaemonActor
import
scala.actors.Actor._
import
scala.concurrent.Lock
...
...
@@ -27,7 +28,7 @@ class ParallelSolver(solvers: Solver*) extends Solver(solvers(0).reporter) {
case
class
Solve
(
expr
:
Expr
)
case
class
Result
(
res
:
Option
[
Boolean
])
class
SolverRunner
(
s
:
Solver
)
extends
Actor
{
class
SolverRunner
(
s
:
Solver
)
extends
Daemon
Actor
{
/*
val that = this
...
...
@@ -61,7 +62,7 @@ class ParallelSolver(solvers: Solver*) extends Solver(solvers(0).reporter) {
}
}
class
Coordinator
extends
Actor
{
class
Coordinator
extends
Daemon
Actor
{
def
act
()
:
Unit
=
{
while
(
true
)
{
...
...
This diff is collapsed.
Click to expand it.
src/purescala/RandomSolver.scala
+
36
−
37
View file @
20b48809
package
purescala
//TODO: improve type error? Actually this is weird it does not seem to have any error of type anymore..
//TODO: Model leads to runtype error
//TODO: Halt must be "thread safe", initialize externalrunning from the solve method is not really correct
import
Common._
import
Definitions._
import
Extensions._
...
...
@@ -23,11 +18,6 @@ class RandomSolver(reporter: Reporter, val nbTrial: Option[Int] = None) extends
val
description
=
"Solver applying random testing (QuickCheck-like)"
override
val
shortDescription
=
"QC"
private
val
startingBound
=
2
private
var
bound
=
startingBound
private
val
startingThreshold
=
20
private
var
threshold
=
startingThreshold
private
val
random
=
new
Random
()
private
def
randomType
()
:
TypeTree
=
{
...
...
@@ -38,7 +28,10 @@ class RandomSolver(reporter: Reporter, val nbTrial: Option[Int] = None) extends
}
private
def
randomValue
(
t
:
TypeTree
,
size
:
Int
)
:
Expr
=
t
match
{
case
Int32Type
=>
IntLiteral
(
size
-
random
.
nextInt
(
2
*
size
+
1
))
case
Int32Type
=>
{
val
s
=
if
(
size
<
Int
.
MaxValue
)
size
+
1
else
size
IntLiteral
(
random
.
nextInt
(
s
))
}
case
BooleanType
=>
BooleanLiteral
(
random
.
nextBoolean
())
case
AbstractClassType
(
acd
)
=>
{
val
children
=
acd
.
knownChildren
...
...
@@ -56,7 +49,8 @@ class RandomSolver(reporter: Reporter, val nbTrial: Option[Int] = None) extends
}
}
case
CaseClassType
(
cd
)
=>
{
CaseClass
(
cd
,
cd
.
fields
.
map
(
f
=>
randomValue
(
f
.
getType
,
size
-
1
)))
val
nbFields
=
cd
.
fields
.
size
CaseClass
(
cd
,
cd
.
fields
.
map
(
f
=>
randomValue
(
f
.
getType
,
size
/
nbFields
)))
}
case
AnyType
=>
randomValue
(
randomType
(),
size
)
case
Untyped
=>
error
(
"I don't know what to do"
)
...
...
@@ -72,67 +66,72 @@ class RandomSolver(reporter: Reporter, val nbTrial: Option[Int] = None) extends
private
var
externalRunning
=
true
def
halt
()
{
externalRunning
=
false
}
def
solve
(
expression
:
Expr
)
:
Option
[
Boolean
]
=
{
val
vars
=
variablesOf
(
expression
)
val
nbVars
=
vars
.
size
var
running
=
true
externalRunning
=
true
threshold
=
startingThreshold
bound
=
startingBound
var
result
:
Option
[
Boolean
]
=
None
//bound starts at 1 since it allows to test value like 0, 1, and Leaf of class hierarchy
var
bound
=
1
val
maxBound
=
Int
.
MaxValue
//the threashold depends on the number of variable and the actual range given by the bound
val
thresholdStep
=
nbVars
*
4
var
threshold
=
thresholdStep
var
i
=
0
var
result
:
Option
[
Boolean
]
=
None
var
iteration
=
0
while
(
running
&&
externalRunning
)
{
nbTrial
match
{
case
Some
(
n
)
=>
running
&&=
(
i
<
n
)
case
Some
(
n
)
=>
running
&&=
(
i
teration
<
n
)
case
None
=>
()
}
if
(
i
>
threshold
)
{
threshold
*=
2
bound
*=
2
if
(
iteration
>
threshold
&&
bound
!=
maxBound
)
{
if
(
bound
*
4
<
bound
)
//this is an overflow
bound
=
maxBound
else
bound
*=
2
//exponential growth
threshold
+=
thresholdStep
}
val
var2val
:
Map
[
Identifier
,
Expr
]
=
Map
(
vars
.
map
(
v
=>
(
v
,
randomValue
(
v
.
getType
,
bound
))).
toList
:
_
*
)
//println("trying with : " + var2val)
reporter
.
info
(
"Trying with: "
+
var2val
)
val
evalResult
=
eval
(
var2val
,
expression
,
None
)
evalResult
match
{
case
OK
(
BooleanLiteral
(
true
))
=>
{
//
reporter.info("Example tried but formula was true")
//
continue trying
}
case
OK
(
BooleanLiteral
(
false
))
=>
{
//
reporter.info("
Example tried and formula was false"
)
reporter
.
info
(
"
Found counter example to formula: "
+
var2val
)
result
=
Some
(
false
)
running
=
false
}
/* in any of the following case, simply continue with another assignement */
case
InfiniteComputation
()
=>
{
reporter
.
info
(
"Model seems to lead to divergent computation."
)
result
=
None
running
=
false
//reporter.info("Model seems to lead to divergent computation.")
}
case
RuntimeError
(
msg
)
=>
{
reporter
.
info
(
"Model leads to runtime error: "
+
msg
)
//
reporter.info("Model leads to runtime error: " + msg)
}
case
t
@
TypeError
(
_
,
_
)
=>
{
reporter
.
info
(
"Type error in model evaluation.\n"
+
t
.
msg
)
//
reporter.info("Type error in model evaluation.\n" + t.msg)
}
case
_
=>
{
reporter
.
info
(
" -> candidate model discarded."
)
result
=
None
running
=
false
//reporter.info(" -> candidate model discarded.")
}
}
i
+=
1
i
teration
+=
1
}
result
}
def
halt
()
{
externalRunning
=
false
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment