Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2929: Reorganized folder structure for make script, removed explicit marshalling, erased go-side logging

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