Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/TestResults.ps1 @ 16617

Last change on this file since 16617 was 16617, checked in by hmaislin, 5 years ago

#2929: Added missing levmar dependency libs for amd64 and fixed MultiTest bugs

File size: 7.8 KB
Line 
1[cmdletbinding()]
2param(
3    [int] $WaitToStep = 30,
4    [string] $BenchName = "Pagie_1",
5    [int] $PeelCnt = 3,
6    [int] $EvalCnt = 3,
7    [ValidateSet("method1","method2", "method3")][string] $InitMethod = "method1",
8    [ValidateSet("method1","method2", "method3")][string] $GrowMethod = "method1",
9    [switch] $NoClear,
10    [switch] $UseExisting
11)
12
13$GenerateNew = -not $UseExisting.IsPresent
14$MaxSecondsTimeout = 90
15
16$LogFolder = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "tmplog"
17
18$CLog = Join-Path -Path $LogFolder -ChildPath "CGen_$($BenchName).log"
19$GoLog = Join-Path -Path $LogFolder -ChildPath "GoOut_$($BenchName).log"
20
21$CLogError = Join-Path -Path $LogFolder -ChildPath "CGen_$($BenchName).err"
22$GoLogError = Join-Path -Path $LogFolder -ChildPath "GoOut_$($BenchName).err"
23
24$CExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'testmulti.exe'
25$GoExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'go-code\go-pge\go-pge.exe'
26
27$BenchData = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'go-code\go-pge\data\benchmark'
28$TestDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).trn"
29$TrainDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).tst"
30
31$ConfigData =  Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'go-code\go-pge\config\prob\bench'
32$ConfigDataFile = Join-Path -Path $ConfigData -ChildPath "$($BenchName).cfg"
33
34if(-not $(Test-Path -Path $TestDataFile -PathType Leaf) -or -not $(Test-Path -Path $TrainDataFile -PathType Leaf)) {
35    Write-Error "Train/test file does't exist for benchmark: $TestDataFile"
36    exit 4
37}
38if(-not $(Test-Path -Path $ConfigDataFile -PathType Leaf)) {
39    Write-Error "Configfile doesn't exist for benchmark: $ConfigDataFile"
40    exit 4
41}
42
43if($NoClear.IsPresent) {
44    $Clear = $false
45} else {
46    $Clear = $GenerateNew   
47}
48
49if($GenerateNew) {
50    if(-not $(Test-Path $LogFolder -Type Container)) {
51        New-Item -Path $LogFolder -ItemType Directory -Force
52    }
53
54  if(Test-Path $GoLog -Type Leaf) {
55    Remove-Item -Path $GoLog
56  }
57  if(Test-Path $CLog -Type Leaf) {
58    Remove-Item -Path $CLog
59    }
60    if(Test-Path $GoLogError -Type Leaf) {
61        Remove-Item -Path $GoLogError
62    }
63    if(Test-Path $CLogError -Type Leaf) {
64        Remove-Item -Path $CLogError
65    }
66 
67    $CGenProc = Start-Process -FilePath $CExecutable -ArgumentList "$BenchName -evals=$($EvalCnt) -peel=$($PeelCnt) -iter=$($WaitToStep) -init=$($InitMethod) -grow=$($GrowMethod)" -RedirectStandardOutput $CLog -RedirectStandardError $CLogError -WorkingDirectory $PSScriptRoot -PassThru
68    $StepReached = $false
69    $LastLogLength = 0
70    $Timeout = $MaxSecondsTimeout
71    while(-not $StepReached) {
72        $CGenCont = Get-Content $CLog
73        if($CGenCont | Select-String -Pattern "\*+ StepW: $WaitToStep \*+") {
74            $StepReached = $true
75        }
76        if($LastLogLength -eq $CGenCont.Length) {
77            $Timeout--
78        } else {
79            $Timeout = $MaxSecondsTimeout
80        }
81        if($Timeout -le 0) {
82            $CGenProc | Stop-Process -ErrorAction SilentlyContinue -Force
83            Write-Error "C-data generation timed out!"
84            exit 2
85        }
86        Start-Sleep -Seconds 1
87        $LastLogLength = $CGenCont.Length
88    }
89
90    $CGenProc  | Stop-Process -ErrorAction SilentlyContinue
91
92  $env:GOGC="off"
93  $env:GODEBUG="cgocheck=0"
94  $env:CGO_ENABLED=1
95    $GoGenProc = Start-Process -FilePath $GoExecutable -ArgumentList "-pcfg=prob/bench/$($BenchName).cfg -evals=$($EvalCnt) -peel=$($PeelCnt) -iter=$($WaitToStep) -init=$($InitMethod) -grow=$($GrowMethod)"  -RedirectStandardOutput $GoLog -RedirectStandardError $GoLogError -WorkingDirectory $(Split-Path -Path $GoExecutable -Parent) -PassThru
96    $StepReached = $false
97    $Timeout = $MaxSecondsTimeout
98    $LastLogLength = 0
99    while(-not $StepReached) {
100        $GoGenCont = Get-Content $GoLog
101        if($GoGenCont | Select-String -Pattern "PS\.step\(\)\s+$($WaitToStep)") {
102            $StepReached = $true
103        }
104        if($LastLogLength -eq $CGenCont.Length) {
105            $Timeout--
106        } else {
107            $Timeout = $MaxSecondsTimeout
108        }
109        if($Timeout -le 0) {
110            $GoGenProc | Stop-Process -ErrorAction SilentlyContinue -Force
111            Write-Error "Go-data generation timed out!"
112            exit 3
113        }
114        Start-Sleep -Seconds 1
115        $LastLogLength = $CGenCont.Length
116    }
117    $GoGenProc | Stop-Process -ErrorAction SilentlyContinue
118}
119
120# Read Result
121
122function Get-CSteps {
123    param([Object[]] $Content)
124    $ValueList = @{}
125    $CurrentStep = 0
126    foreach($Line in $Content) {
127        if($Line -match "\*+ StepW: (\d+) \*+") {
128            [int]$CurrentStep = $Matches[1]
129            $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
130        } elseif($Line -match "push\/pop \(\d+\,\d+\) (.+)") {
131            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
132        }
133    }
134    return $ValueList
135}
136
137function Get-GoSteps {
138    param([Object[]] $Content)
139    $ValueList = @{}
140    $CurrentStep = 0
141    foreach($Line in $Content) {
142        if($Line -match "PS\.step\(\)\s+(\d+)") {
143            [int]$CurrentStep = $Matches[1]
144            $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
145        } elseif($Line -match "pop\/push\(\d+\,\d+\)\: (.+)") {
146            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
147        }
148    }
149    return $ValueList
150}
151
152function Compare-Results {
153    param(
154        [string]$First,
155        [string]$Second
156    )
157    $FirstChars = $First.Trim().ToUpper().ToCharArray() | Sort-Object
158    $SecondChars = $Second.Trim().ToUpper().ToCharArray() | Sort-Object
159
160    [System.Collections.ArrayList]$LeftChars = $SecondChars.Clone()
161    $FirstCharNr = 0
162    foreach($FirstChar in $FirstChars) {
163        $SecondChar = $SecondChars[$FirstCharNr]
164        if($FirstChar -eq $SecondChar) {
165            $LeftChars.Remove($FirstChar)
166        } else {
167            return $false
168        }
169        $FirstCharNr++
170    }
171    return [bool]($LeftChars.Count -eq 0)
172}
173
174$CContent = Get-Content -Path $CLog
175$GoContent = Get-Content -Path $GoLog
176
177$ParseC = Get-CSteps -Content $CContent
178$ParseGo = Get-GoSteps -Content $GoContent
179
180for($StepNr = 1; $StepNr -le $WaitToStep; $StepNr++) {
181    $GoResult = $ParseGo[$StepNr]
182    [System.Collections.ArrayList]$CResult = $ParseC[$StepNr]
183    if($null -eq $GoResult -or $null -eq $CResult) {
184        $StepResult = $false
185    } else {
186        $StepResult = $CResult.Count -eq $GoResult.Count
187    }
188    if($StepResult) {   
189        foreach($GoRes in $GoResult) {            # Step Results
190            $State = $false
191            foreach($CRes in $CResult.Clone()) {  # Compare every Result with every Step Result
192                Write-Debug "$($GoRes) with $($CRes)"
193                if(Compare-Results -First $GoRes -Second $CRes) {
194                    $State = $true
195                    $CResult.Remove($CRes)
196                    break
197                }
198            }
199            if(-not $State) {
200                $StepResult = $false
201            }
202        }
203    }
204
205    if($StepResult) {
206        Write-Output "$StepNr OK"
207    } else {
208        Write-Warning "$StepNr failed!"
209    }
210}
211
212if($Clear) {
213    if(Test-Path $GoLog -Type Leaf) {
214        Remove-Item -Path $GoLog
215    }
216    if(Test-Path $CLog -Type Leaf) {
217        Remove-Item -Path $CLog
218    }
219    if(Test-Path $GoLogError -Type Leaf) {
220        Remove-Item -Path $GoLogError
221    }
222    if(Test-Path $CLogError -Type Leaf) {
223        Remove-Item -Path $CLogError
224    }
225}
Note: See TracBrowser for help on using the repository browser.