merge with dev (update to Kotlin 1.9.0)

This commit is contained in:
chernov 2023-10-09 15:29:00 +03:00
parent 7659bc41a0
commit bc77af263b
4 changed files with 84 additions and 12 deletions

View File

@ -2,11 +2,27 @@
// Source: ru.inr.mass.data.proto.Point in numass-proto.proto // Source: ru.inr.mass.data.proto.Point in numass-proto.proto
package ru.inr.mass.`data`.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.Syntax.PROTO_3
import com.squareup.wire.internal.JvmField import com.squareup.wire.WireField
import com.squareup.wire.internal.immutableCopyOf import com.squareup.wire.`internal`.JvmField
import com.squareup.wire.internal.redactElements 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 import okio.ByteString
public class Point( public class Point(

View File

@ -2,6 +2,7 @@ plugins {
id("space.kscience.gradle.jvm") id("space.kscience.gradle.jvm")
id("com.github.johnrengelman.shadow") version "7.1.2" id("com.github.johnrengelman.shadow") version "7.1.2"
`maven-publish` `maven-publish`
// application
} }
kotlin { kotlin {
@ -9,7 +10,7 @@ kotlin {
} }
val dataforgeVersion: String by rootProject.extra val dataforgeVersion: String by rootProject.extra
val visionForgeVersion: String by rootProject.extra val plotlyKtVersion = "0.6.0"
val kmathVersion: String by rootProject.extra val kmathVersion: String by rootProject.extra
val tablesVersion: String by rootProject.extra val tablesVersion: String by rootProject.extra
@ -21,9 +22,15 @@ dependencies {
implementation("space.kscience:kmath-jupyter:$kmathVersion") implementation("space.kscience:kmath-jupyter:$kmathVersion")
implementation("space.kscience:tables-kt:$tablesVersion") 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{ kscience{
jupyterLibrary("ru.inr.mass.notebook.NumassJupyter") jupyterLibrary("ru.inr.mass.notebook.NumassJupyter")
} }
//application {
// mainClass.set("ru.inr.mass.scripts.Spectrum_serverKt")
//}

View File

@ -3,12 +3,12 @@ package ru.inr.mass.scripts
import ru.inr.mass.models.* import ru.inr.mass.models.*
import ru.inr.mass.workspace.buffer import ru.inr.mass.workspace.buffer
import ru.inr.mass.workspace.fitWith import ru.inr.mass.workspace.fitWith
import space.kscience.kmath.UnstableKMathAPI
import space.kscience.kmath.data.XYColumnarData import space.kscience.kmath.data.XYColumnarData
import space.kscience.kmath.data.XYErrorColumnarData import space.kscience.kmath.data.XYErrorColumnarData
import space.kscience.kmath.data.indices import space.kscience.kmath.data.indices
import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.expressions.derivative import space.kscience.kmath.expressions.derivative
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.operations.asSequence import space.kscience.kmath.operations.asSequence
import space.kscience.kmath.optimization.* import space.kscience.kmath.optimization.*
import space.kscience.kmath.real.step import space.kscience.kmath.real.step
@ -18,6 +18,7 @@ import space.kscience.plotly.models.ScatterMode
import java.io.File import java.io.File
import kotlin.math.pow import kotlin.math.pow
@OptIn(UnstableKMathAPI::class)
fun parse(filename: String): XYErrorColumnarData<Double, Double, Double> { fun parse(filename: String): XYErrorColumnarData<Double, Double, Double> {
val x: MutableList<Double> = mutableListOf() val x: MutableList<Double> = mutableListOf()
val y: MutableList<Double> = mutableListOf() val y: MutableList<Double> = mutableListOf()
@ -37,8 +38,12 @@ fun parse(filename: String): XYErrorColumnarData<Double, Double, Double> {
) )
} }
@OptIn(UnstableKMathAPI::class) //@OptIn(UnstableKMathAPI::class)
@UnstableKMathAPI
suspend fun main() { suspend fun main() {
// val fitParams = FitParams().main(args);
val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum( val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum(
// fss = FSS.default, // fss = FSS.default,
transmission = NumassTransmission(NumassTransmission.trapFunction), transmission = NumassTransmission(NumassTransmission.trapFunction),
@ -64,7 +69,7 @@ suspend fun main() {
// //
// val strategy = (12000.0..19000.0 step 100.0).asSequence().associateWith { timePerPoint } // 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( val fit: XYFit = data.fitWith(
optimizer = QowOptimizer, optimizer = QowOptimizer,
@ -74,7 +79,7 @@ suspend fun main() {
OptimizationIterations(20) OptimizationIterations(20)
) )
//println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}") println(fit.resultPoint)
Plotly.page { Plotly.page {
plot { plot {
@ -92,7 +97,7 @@ suspend fun main() {
mode = ScatterMode.lines mode = ScatterMode.lines
x.buffer = 12000.0..18600.0 step 50.0 x.buffer = 12000.0..18600.0 step 50.0
y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) } 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 { y.numbers.forEach {
out.println(it) out.println(it)
} }

View File

@ -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<String>) {
val cli = args.map { it.toDouble() }
val args: Map<Symbol, Double> = 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"))
}
}