I really love kotlin. A hour of work, fifty lines ...
# science
a
I really love kotlin. A hour of work, fifty lines of code and we have dynamic visualization of fully parallel and reactive stream-based simulation of terrestrial gamma-flashes (reactor model). The code is not yet publication-ready, but you can look at it here. Flows are really great for Monte-Carlo simulations (cc @elizarov).
❤️ 1
Try to do that in Python
b
What's the volume of data processed?
a
It is simulation. It is limited by million events per generation and significantly slower down by adding delay between generations (otherwise it completes emmediately and I can't show the dynamic picture).
b
nice
h
What lib are you using here? Letsplot?
a
Nope, Plotly.kt.
In this regard we are following JB dogfooding practice. I am currently working on a more universal system, which will allow to show not only plots, but more general visual data as well.
h
Awesome, what would be most awesome if such a framework would also support controls. E.g. to modulate simulation speed etc. Is there a public repo already?
a
The controls are planed, yes. The frontend controlls are possible to do in plotlykt-server right now, but I want more general solution. Also you can see JavaFX demo for plotlykt: https://github.com/mipt-npm/plotly.kt/tree/master/fx-demo. It include controls for the plot. The repository for visionforge is here: https://github.com/mipt-npm/visionforge. And demos include custom controls. Right now you need to manually create frontend multiplatform module, but in the end it will be possible to define it on the backend like Dash does on python.
z
Hi @altavir can we use these modules in any of the community editions of the JB tools? If yes can you please name them.
a
@zain yes, you do not need JB tools for anything. It is just regular kotlin-jvm code. Plotly.kt is ready to public use. VisionForge just got the update, which allows to use the same functionality, namely defining models on JVM and rendering them automatically on the frontend without any Kotlin-JS injections.
z
This is not a library issue but having difficulties integrating the library in Intellij. facing this issues https://stackoverflow.com/q/48988778/4083142 tried all the suggested options but still the compiler is throwing the error. Trying to run this specific implementation.
Copy code
import hep.dataforge.meta.invoke
import kscience.plotly.Plotly
import kscience.plotly.makeFile
import kscience.plotly.models.Pie

/**
 * - basic pie chart
 * - change height and width of the plot
 */
fun main() {
    val values = listOf(19, 26, 55)
    val labels = listOf("Residential", "Non-Residential", "Utility")

    val pie = Pie {
        values(values)
        labels(labels)
    }

    val plot = Plotly.plot {
        traces(pie)
        layout {
            width = 500
            height = 450
        }
    }

    plot.makeFile()
}
Hi @altavir created a question can you please help me out if possible https://stackoverflow.com/q/65237210/4083142
a
Yes, it is a known problem. You have to use Java 8 as a compiler.
The problem is that Plotly.kt is compiled using JDK 8 (it will be 11 in future releases). And you are trying to use Kotlin 1.6 compiler and calling inline functions. There are two solutions for that: - You can avoid using inline functions (they are there only for convenience). - You can switch the compiled code version to 1.8 via Idea project settings or gradle.
The second question is also about JDK version, so all you need is to use newer JDK and set the bytecode version to 1.8
z
Thanks @altavir it got resolved