From bc77af263b15064eef28429ba1c62b856900c0cc Mon Sep 17 00:00:00 2001 From: chernov Date: Mon, 9 Oct 2023 15:29:00 +0300 Subject: [PATCH] merge with dev (update to Kotlin 1.9.0) --- .../kotlin/ru/inr/mass/data/proto/Point.kt | 24 ++++++++-- numass-workspace/build.gradle.kts | 13 ++++-- .../main/kotlin/ru/inr/mass/scripts/fit.kt | 15 ++++--- .../ru/inr/mass/scripts/get-spectrum.kt | 44 +++++++++++++++++++ 4 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 numass-workspace/src/main/kotlin/ru/inr/mass/scripts/get-spectrum.kt diff --git a/numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt b/numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt index ee8a3c2..de1bc97 100644 --- a/numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt +++ b/numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt @@ -2,11 +2,27 @@ // Source: ru.inr.mass.data.proto.Point in numass-proto.proto package ru.inr.mass.`data`.proto -import com.squareup.wire.* +import com.squareup.wire.FieldEncoding +import com.squareup.wire.Message +import com.squareup.wire.ProtoAdapter +import com.squareup.wire.ProtoReader +import com.squareup.wire.ProtoWriter +import com.squareup.wire.ReverseProtoWriter import com.squareup.wire.Syntax.PROTO_3 -import com.squareup.wire.internal.JvmField -import com.squareup.wire.internal.immutableCopyOf -import com.squareup.wire.internal.redactElements +import com.squareup.wire.WireField +import com.squareup.wire.`internal`.JvmField +import com.squareup.wire.`internal`.immutableCopyOf +import com.squareup.wire.`internal`.redactElements +import kotlin.Any +import kotlin.AssertionError +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel +import kotlin.Int +import kotlin.Long +import kotlin.Nothing +import kotlin.String +import kotlin.collections.List import okio.ByteString public class Point( diff --git a/numass-workspace/build.gradle.kts b/numass-workspace/build.gradle.kts index 18e9212..4ed4d30 100644 --- a/numass-workspace/build.gradle.kts +++ b/numass-workspace/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("space.kscience.gradle.jvm") id("com.github.johnrengelman.shadow") version "7.1.2" `maven-publish` +// application } kotlin { @@ -9,7 +10,7 @@ kotlin { } val dataforgeVersion: String by rootProject.extra -val visionForgeVersion: String by rootProject.extra +val plotlyKtVersion = "0.6.0" val kmathVersion: String by rootProject.extra val tablesVersion: String by rootProject.extra @@ -21,9 +22,15 @@ dependencies { implementation("space.kscience:kmath-jupyter:$kmathVersion") implementation("space.kscience:tables-kt:$tablesVersion") - implementation("space.kscience:visionforge-plotly:$visionForgeVersion") + implementation("space.kscience:plotlykt-core:$plotlyKtVersion") + + implementation("com.github.ajalt.clikt:clikt:4.2.1") } kscience{ jupyterLibrary("ru.inr.mass.notebook.NumassJupyter") -} \ No newline at end of file +} + +//application { +// mainClass.set("ru.inr.mass.scripts.Spectrum_serverKt") +//} \ No newline at end of file diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/fit.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/fit.kt index 2532f9d..0fdf198 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/fit.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/fit.kt @@ -3,12 +3,12 @@ package ru.inr.mass.scripts import ru.inr.mass.models.* import ru.inr.mass.workspace.buffer import ru.inr.mass.workspace.fitWith +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.data.XYColumnarData import space.kscience.kmath.data.XYErrorColumnarData import space.kscience.kmath.data.indices import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.derivative -import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.asSequence import space.kscience.kmath.optimization.* import space.kscience.kmath.real.step @@ -18,6 +18,7 @@ import space.kscience.plotly.models.ScatterMode import java.io.File import kotlin.math.pow +@OptIn(UnstableKMathAPI::class) fun parse(filename: String): XYErrorColumnarData { val x: MutableList = mutableListOf() val y: MutableList = mutableListOf() @@ -37,8 +38,12 @@ fun parse(filename: String): XYErrorColumnarData { ) } -@OptIn(UnstableKMathAPI::class) +//@OptIn(UnstableKMathAPI::class) +@UnstableKMathAPI suspend fun main() { + +// val fitParams = FitParams().main(args); + val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum( // fss = FSS.default, transmission = NumassTransmission(NumassTransmission.trapFunction), @@ -64,7 +69,7 @@ suspend fun main() { // // val strategy = (12000.0..19000.0 step 100.0).asSequence().associateWith { timePerPoint } - val data = parse("/home/sabina/Numass/Fit/Data/03.10.2023") + val data = parse("/home/chernov/projects/notebooks/manual-fit/06.10.2023") val fit: XYFit = data.fitWith( optimizer = QowOptimizer, @@ -74,7 +79,7 @@ suspend fun main() { OptimizationIterations(20) ) - //println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}") + println(fit.resultPoint) Plotly.page { plot { @@ -92,7 +97,7 @@ suspend fun main() { mode = ScatterMode.lines x.buffer = 12000.0..18600.0 step 50.0 y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) } - File("/home/sabina/Numass/Fit/trap1").printWriter().use { out -> + File("/home/chernov/projects/notebooks/manual-fit/04.10.2023-fit").printWriter().use { out -> y.numbers.forEach { out.println(it) } diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/get-spectrum.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/get-spectrum.kt new file mode 100644 index 0000000..a556d0b --- /dev/null +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/get-spectrum.kt @@ -0,0 +1,44 @@ +package ru.inr.mass.scripts + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import ru.inr.mass.models.* +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.operations.toTypedArray +import space.kscience.kmath.real.plus +import space.kscience.kmath.real.step + +fun main(args: Array) { + val cli = args.map { it.toDouble() } + + val args: Map = mapOf( + NBkgSpectrum.norm to cli[0], + NBkgSpectrum.bkg to cli[1], + NumassBeta.mnu2 to cli[2], + NumassBeta.e0 to cli[3], + NumassBeta.msterile2 to cli[4], + NumassBeta.u2 to cli[5], + NumassTransmission.thickness to cli[6], + NumassTransmission.trap to cli[7] + ) + + runBlocking(Dispatchers.Default) { + val range = (12000.0..16000.0 step 50.0).toTypedArray() + .plus((16100.0..18600.0 step 100.0).toTypedArray()); + + val handles = range.map { + + async(Dispatchers.Default) { + val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum( + transmission = NumassTransmission(NumassTransmission.trapFunction), + ).withNBkg() + + val res = spectrum.invoke(it, args) + return@async res + } + } + val out = handles.map { it.await() } + println(out.joinToString("\n")) + } +} \ No newline at end of file