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
RevLine 
[16614]1[cmdletbinding()]
2param(
[16618]3    [int] $WaitToStep = 200,
4    [parameter(Position=0)][string] $BenchName = "Pagie_1",
[16614]5    [int] $PeelCnt = 3,
6    [int] $EvalCnt = 3,
7    [ValidateSet("method1","method2", "method3")][string] $InitMethod = "method1",
8    [ValidateSet("method1","method2", "method3")][string] $GrowMethod = "method1",
[16617]9    [switch] $NoClear,
[16618]10    [switch] $UseExisting,
11    [int]$MaxSecondsTimeout = 1500
[16533]12)
13
[16617]14$GenerateNew = -not $UseExisting.IsPresent
[16533]15
[16617]16$LogFolder = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "tmplog"
[16533]17
[16618]18$CLog = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_CGen.log"
19$GoLog = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_GoOut.log"
[16614]20
[16618]21$CLogError = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_CGen.err"
22$GoLogError = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_GoOut.err"
[16617]23
[16620]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'
[16533]26
[16620]27$BenchData = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\data\benchmark'
[16617]28$TestDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).trn"
29$TrainDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).tst"
30
[16620]31$ConfigData =  Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\config\prob\bench'
[16617]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
[16618]49$env:GOGC="off"
50$env:GODEBUG="cgocheck=0"
51$env:CGO_ENABLED=1
[16617]52
[16618]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)) {
[16614]58  if(Test-Path $CLog -Type Leaf) {
59    Remove-Item -Path $CLog
60    }
[16618]61   if(Test-Path $CLogError -Type Leaf) {
62      Remove-Item -Path $CLogError
63   }
[16620]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
[16533]65    $StepReached = $false
[16617]66    $LastLogLength = 0
67    $Timeout = $MaxSecondsTimeout
[16533]68    while(-not $StepReached) {
69        $CGenCont = Get-Content $CLog
70        if($CGenCont | Select-String -Pattern "\*+ StepW: $WaitToStep \*+") {
71            $StepReached = $true
72        }
[16618]73        if(-not $StepReached -and $LastLogLength -eq $CGenCont.Length) {
[16617]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        }
[16618]83        $LastLogLength = $CGenCont.Length
[16533]84        Start-Sleep -Seconds 1
85    }
86    $CGenProc  | Stop-Process -ErrorAction SilentlyContinue
[16618]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  }
[16614]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
[16533]97    $StepReached = $false
[16617]98    $Timeout = $MaxSecondsTimeout
99    $LastLogLength = 0
[16533]100    while(-not $StepReached) {
101        $GoGenCont = Get-Content $GoLog
102        if($GoGenCont | Select-String -Pattern "PS\.step\(\)\s+$($WaitToStep)") {
103            $StepReached = $true
104        }
[16617]105        if($LastLogLength -eq $CGenCont.Length) {
106            $Timeout--
107        } else {
108            $Timeout = $MaxSecondsTimeout
109        }
[16618]110        if(-not $StepReached -and $Timeout -le 0) {
[16617]111            $GoGenProc | Stop-Process -ErrorAction SilentlyContinue -Force
112            Write-Error "Go-data generation timed out!"
113            exit 3
114        }
[16618]115        $LastLogLength = $CGenCont.Length
[16533]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)
[16614]131        } elseif($Line -match "push\/pop \(\d+\,\d+\) (.+)") {
132            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
[16533]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+\)\: (.+)") {
[16614]147            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
[16533]148        }
149    }
150    return $ValueList
151}
152
153function Compare-Results {
154    param(
155        [string]$First,
156        [string]$Second
157    )
[16614]158    $FirstChars = $First.Trim().ToUpper().ToCharArray() | Sort-Object
159    $SecondChars = $Second.Trim().ToUpper().ToCharArray() | Sort-Object
[16533]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
[16617]181for($StepNr = 1; $StepNr -le $WaitToStep; $StepNr++) {
[16533]182    $GoResult = $ParseGo[$StepNr]
[16614]183    [System.Collections.ArrayList]$CResult = $ParseC[$StepNr]
[16617]184    if($null -eq $GoResult -or $null -eq $CResult) {
185        $StepResult = $false
186    } else {
187        $StepResult = $CResult.Count -eq $GoResult.Count
[16533]188    }
[16617]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                }
[16533]199            }
[16617]200            if(-not $State) {
201                $StepResult = $false
202            }
[16533]203        }
204    }
205
206    if($StepResult) {
[16614]207        Write-Output "$StepNr OK"
[16533]208    } else {
209        Write-Warning "$StepNr failed!"
210    }
211}
[16614]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.