Skip to content

Commit

Permalink
update versions and disable highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jul 16, 2023
1 parent 4814022 commit e8806be
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
plugins {
signing
`maven-publish`
kotlin("multiplatform") version "1.9.0-RC"
kotlin("multiplatform") version "1.9.0"
// kotlin("jupyter.api") version "0.11.0-225"
id("com.github.ben-manes.versions") version "0.47.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0-rc-1"
Expand Down Expand Up @@ -133,7 +133,7 @@ kotlin {
implementation("org.graalvm.js:js:23.0.0")

// Markovian deps
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")

implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:$kotlinxVersion") // TODO: why is this necessary?
implementation("org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.4.1")
Expand Down Expand Up @@ -175,7 +175,7 @@ kotlin {
implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
implementation("io.kotest:kotest-property:$kotestVersion")
implementation("org.junit.jupiter:junit-jupiter:5.10.0-M1")
implementation("org.junit.jupiter:junit-jupiter:5.10.0-RC1")

implementation("junit:junit:4.13.2")
implementation("org.jetbrains:annotations:24.0.1")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,67 @@ fun bijectiveRepair(
return ::genSeq.parallelize().distinct().asSequence()
}

fun bijectiveRepairST(
promptTokens: List<Σᐩ>,
// A list of tokens to be used as fillers (may contain repeats for higher probability of sampling)
deck: List<Σᐩ>,
// Optional parameter that gives sampler hints about which locations contain errors
hints: List<Int> = emptyList(),
maxEdits: Int = 2,
takeMoreWhile: () -> Boolean = { true },
admissibilityFilter: List<Σᐩ>.() -> Boolean = { true },
diagnostic: ((Repair) -> Unit)? = null,
scoreEdit: (List<Σᐩ>) -> Double = { 0.0 },
): Sequence<Repair> {
// println("Repairing: $promptTokens")
// println("Fillers: $fillers")
// println("Using deck: $deck")
val deckUnique = deck.toSet()
val clock: TimeSource.Monotonic.ValueTimeMark = TimeSource.Monotonic.markNow()
var (pass, fail) = 0 to 0

val seen = ConcurrentSkipListSet<Int>()
val goodEdits = ConcurrentRankedProbabilisticSet<Edit>()

fun genSeq(skip: Int = 1, shift: Int = 0): Sequence<Repair> =
// This samples edits uniformly at random without replacement (extremely fast)
MDSamplerWithoutReplacementNK(deckUnique, n = promptTokens.size, k = maxEdits, skip, shift)
.takeWhile { takeMoreWhile() }
.flatMap {
val schedule = (clock.elapsedNow().inWholeMilliseconds / 200)
.toInt().coerceAtMost(3)
// 1 to 3 is one "explore" (uniform random) to five exploit (resampled good edits)
listOf(it) + (
if (hints.isEmpty() && goodEdits.isEmpty()) emptyList()
else if (hints.isNotEmpty() && goodEdits.isEmpty())
genDefaultEdits(hints, maxEdits, deck, seen).take(10).toList()
else goodEdits.resample(
maxTake = 1 + schedule, // This controls the growth rate of the resampling ratio
strLen = promptTokens.size,
deck = deck,
seen = seen
)
)
}
.map { it: Edit ->
val result = promptTokens.apply(it)
Repair(promptTokens, it, result, 0.0)
}
// This is slow, so let's rerank by score only after filtering
// .let { it.reservoirSample(score = { it.score }) }
.onEach { seen.add(it.hashCode()) }
.filter { it.result.admissibilityFilter() }
.flatMap { it.minimalAdmissibleSubrepairs(admissibilityFilter, scoreEdit) }
.onEach {
goodEdits.add(it.edit, it.score)
it.timeMS = clock.elapsedNow().inWholeMilliseconds
if (diagnostic != null) { diagnostic(it) }
}

/** Selects distinct repairs according to [Repair.hashCode] */
return genSeq().distinct()
}

// This experiment essentially tries every possible combination of fillers in parallel
fun List<Σᐩ>.parallelSolve(fillers: Set<Σᐩ>) =
MDSamplerWithoutReplacement(fillers, count { it == HOLE_MARKER })
Expand Down

0 comments on commit e8806be

Please sign in to comment.