Skip to content

Commit

Permalink
add study notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
mandoway committed Oct 16, 2024
1 parent 2ff654d commit 789cb45
Showing 1 changed file with 187 additions and 0 deletions.
187 changes: 187 additions & 0 deletions study/base.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": [
"# Base study\n",
"\n",
"This file contains code to run the evaluation for the base study for all instances\n",
"\n",
"Evaluation runs:\n",
"- Baseline with Perses & Vulcan\n",
"- SeRu with Perses & Vulcan"
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Setup"
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-10-16T17:50:25.175235Z",
"start_time": "2024-10-16T17:49:38.812844Z"
}
},
"source": [
"%use dataframe\n",
"%use kandy"
],
"outputs": [],
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-16T19:10:37.503791Z",
"start_time": "2024-10-16T19:10:37.370004Z"
}
},
"cell_type": "code",
"source": [
"import kotlin.io.path.Path\n",
"import kotlin.io.path.listDirectoryEntries\n",
"import kotlin.io.path.walk\n",
"import java.io.IOException\n",
"import java.util.concurrent.TimeUnit\n",
"\n",
"val ignoredIssues = listOf(\"issue_2\", \"issue_2490\")\n",
"val instances = File(\"instances\")\n",
" .walk()\n",
" .filter { it.isDirectory && (it.name.startsWith(\"f\") || it.name.startsWith(\"v\")) }\n",
" .filter { ignoredIssues.all { issue -> !it.parent.endsWith(issue) } }\n",
" .map { it.toPath() }\n",
"\n",
"data class CommandOutput(val stdout: String, val stderr: String)\n",
"\n",
"fun String.runCommand(workingDir: File): CommandOutput? {\n",
" return try {\n",
" ProcessBuilder(*split(\" \").toTypedArray())\n",
" .directory(workingDir)\n",
" .redirectOutput(ProcessBuilder.Redirect.PIPE)\n",
" .redirectError(ProcessBuilder.Redirect.PIPE)\n",
" .start()\n",
" .also { it.waitFor(60, TimeUnit.MINUTES) }\n",
" .let {\n",
" CommandOutput(\n",
" stdout = it.inputStream.bufferedReader().readText(),\n",
" stderr = it.errorStream.bufferedReader().readText()\n",
" )\n",
" }\n",
" } catch (e: IOException) {\n",
" e.printStackTrace()\n",
" null\n",
" }\n",
"}\n",
"\n",
"fun String.runCommandInRoot() = runCommand(File(\"..\"))"
],
"outputs": [],
"execution_count": 53
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Compile SeRu"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-16T18:30:40.362381Z",
"start_time": "2024-10-16T18:30:39.753409Z"
}
},
"cell_type": "code",
"source": [
"\"go generate ./...\".runCommandInRoot()\n",
"\"go build\".runCommandInRoot()"
],
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 41
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-16T19:11:56.742125Z",
"start_time": "2024-10-16T19:11:56.708625Z"
}
},
"cell_type": "code",
"source": [
"import java.nio.file.Path\n",
"\n",
"fun runSeruIn(folder: Path) = \"./seru -i ${folder.pathString}/in.cue -t ${folder.pathString}/test.sh -m\".runCommandInRoot()"
],
"outputs": [],
"execution_count": 54
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-16T19:12:34.224662Z",
"start_time": "2024-10-16T19:12:11.452754Z"
}
},
"cell_type": "code",
"source": [
"import kotlin.io.path.*\n",
"\n",
"val results = Path(\"results\").createDirectory()\n",
"\n",
"instances.forEach { instance ->\n",
" val instanceDir = (results / instance).createDirectories()\n",
" val output = runSeruIn(Path(\"study\") / instance)\n",
" \n",
" Path(\"..\")\n",
" .listDirectoryEntries(glob = \"seru*\")\n",
" .maxBy { it.getLastModifiedTime() }\n",
" .moveTo(instanceDir / \"seru_result\")\n",
" \n",
" output ?: return@forEach\n",
" (instanceDir / \"log.txt\").writeBytes(output.stdout.toByteArray())\n",
" (instanceDir / \"err.txt\").writeBytes(output.stderr.toByteArray())\n",
"}"
],
"outputs": [],
"execution_count": 55
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": ""
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"name": "kotlin",
"version": "1.9.23",
"mimetype": "text/x-kotlin",
"file_extension": ".kt",
"pygments_lexer": "kotlin",
"codemirror_mode": "text/x-kotlin",
"nbconvert_exporter": ""
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 789cb45

Please sign in to comment.