Skip to content

Commit

Permalink
Many Javascript bug fixes 🪲
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNewJavaman committed Dec 7, 2021
1 parent f4aa5c6 commit 590febe
Show file tree
Hide file tree
Showing 38 changed files with 2,278 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle/
.idea/
*.hprof

build/
*/build/
*/node_modules/
*/dist/
16 changes: 16 additions & 0 deletions brac-kt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kotlin {
}
}
js(IR) {
moduleName = "brac-kt-api"
browser {
testTask {
useKarma {
Expand All @@ -39,6 +40,21 @@ kotlin {
useMocha {}
}
}
compilations["main"].packageJson {
customField("name" to "@thenewjavaman/brac-kt-api")
customField("description" to "A Kotlin/Multiplatform interface for quantum computing")
customField("homepage" to "https://github.com/TheNewJavaman/brac-kt")
customField("author" to mapOf(
"name" to "Gabriel Pizarro",
"email" to "[email protected]",
"url" to "https://javaman.net"
))
customField("repository" to mapOf(
"type" to "git",
"url" to "https://github.com/TheNewJavaman/brac-kt"
))
customField("private" to false)
}
binaries.executable()
}
sourceSets {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.api.quantum

import net.javaman.brackt.api.util.assertions.assert
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.js.JsName
import kotlin.jvm.JvmOverloads

/**
Expand All @@ -25,6 +30,7 @@ import kotlin.jvm.JvmOverloads
* ```
*/
@Suppress("TooManyFunctions") // Needs all QuantumGates
@JsExport
class QuantumCircuit @JvmOverloads constructor(
val name: String? = null,
val numQubits: Int,
Expand All @@ -33,6 +39,7 @@ class QuantumCircuit @JvmOverloads constructor(
//private val bits: List<Bit> = List(numBits) { Bit(it) },
val circuit: MutableList<QuantumGate> = mutableListOf()
) {
@JsName("QuantumCircuitCompose")
constructor(
name: String? = null,
numQubits: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.api.quantum

import net.javaman.brackt.api.util.assertions.assert
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.jvm.JvmStatic

/**
Expand All @@ -19,6 +23,7 @@ import kotlin.jvm.JvmStatic
* }
* ```
*/
@JsExport
class QuantumMacro(val numQubits: Int, val macro: QuantumCircuit.(qubitMap: QubitMap) -> Unit) {
var safeMacro: QuantumCircuit.(qubitMap: QubitMap) -> Unit

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.api.util.assertions

import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

/**
* Assert conditions in pure Kotlin and a clean syntax
*/
@JsExport
fun assert(block: () -> Boolean) {
if (!block()) throw AssertionException("Assertion failed")
}

@JsExport
class AssertionException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.api.util.logging

import kotlinx.datetime.Clock
import net.javaman.brackt.api.util.formatters.PadDirection
import net.javaman.brackt.api.util.formatters.pretty
import net.javaman.brackt.api.util.formatters.withLength
import net.javaman.brackt.api.util.reflection.getPlatformQualifiedName
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.js.JsName
import kotlin.jvm.JvmStatic
import kotlin.reflect.KClass

/**
* Prints well-formatted messages to the console using pure Kotlin and a clean syntax. Useful for multiplatform projects
*/
@JsExport
class Logger(val className: String) {
companion object {
@JvmStatic
Expand All @@ -22,7 +28,7 @@ class Logger(val className: String) {
val LEVEL_CHARS = LoggingLevel.values().maxOf { it.name.length }
}

constructor(kClass: KClass<*>) : this(kClass.getPlatformQualifiedName())
@JsName("LoggerByClass") constructor(kClass: KClass<*>) : this(kClass.getPlatformQualifiedName())

fun log(level: LoggingLevel, block: () -> Any) {
if (acceptableLevel.severity <= level.severity) {
Expand Down
16 changes: 16 additions & 0 deletions brac-kt-ibmq-provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ kotlin {
}
}
js(IR) {
moduleName = "brac-kt-ibmq-provider"
browser {
testTask {
useKarma {
Expand All @@ -41,6 +42,21 @@ kotlin {
useMocha {}
}
}
compilations["main"].packageJson {
customField("name" to "@thenewjavaman/brac-kt-ibmq-provider")
customField("description" to "A Kotlin/Multiplatform interface for quantum computing")
customField("homepage" to "https://github.com/TheNewJavaman/brac-kt")
customField("author" to mapOf(
"name" to "Gabriel Pizarro",
"email" to "[email protected]",
"url" to "https://javaman.net"
))
customField("repository" to mapOf(
"type" to "git",
"url" to "https://github.com/TheNewJavaman/brac-kt"
))
customField("private" to false)
}
binaries.executable()
}
sourceSets {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq

import io.ktor.client.request.get
Expand Down Expand Up @@ -30,6 +32,8 @@ import net.javaman.brackt.providers.ibmq.api.models.RunExperimentResponse
import net.javaman.brackt.providers.ibmq.api.models.VersionsRequest
import net.javaman.brackt.providers.ibmq.api.models.VersionsResponse
import net.javaman.brackt.providers.ibmq.transpiler.toQasm
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.js.JsName
import kotlin.jvm.JvmStatic
import kotlin.time.Duration
Expand Down Expand Up @@ -60,7 +64,7 @@ class IbmqProvider {

@OptIn(ExperimentalTime::class)
@JvmStatic
private val JOB_TIMEOUT_DURATION = 5.minutes
val JOB_TIMEOUT_DURATION = 5.minutes

@OptIn(ExperimentalTime::class)
@JvmStatic
Expand Down Expand Up @@ -303,6 +307,8 @@ class IbmqProvider {
}
}

@JsExport
class DeviceNotAvailableException(message: String) : Exception(message)

@JsExport
class JobTimeoutException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api

import io.ktor.client.request.get
Expand Down Expand Up @@ -25,6 +27,8 @@ import net.javaman.brackt.providers.ibmq.api.models.RunExperimentRequest
import net.javaman.brackt.providers.ibmq.api.models.RunExperimentResponse
import net.javaman.brackt.providers.ibmq.api.models.VersionsRequest
import net.javaman.brackt.providers.ibmq.api.models.VersionsResponse
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

/**
* An HTTP client for [IBM Quantum](https://quantum-computing.ibm.com/)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@file:Suppress("MatchingDeclarationName") // Keep the naming convention of the package
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api.models

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@JsExport
@Serializable
data class ApiTokenResponse(
val apiToken: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api.models

import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

typealias BackendsResponse = List<BackendResponse>

@JsExport
@Serializable
data class BackendResponse(
val hasAccess: Boolean,
Expand All @@ -25,6 +30,7 @@ data class BackendResponse(
val category: String? = null
)

@JsExport
@Serializable
data class BackendProcessorType(
val family: String,
Expand All @@ -33,6 +39,7 @@ data class BackendProcessorType(
val segment: String? = null
)

@JsExport
@Serializable
data class BackendDeviceStatus(
val state: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api.models

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.Required
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@JsExport
@Serializable
data class Code(
@Required
Expand Down Expand Up @@ -36,19 +41,22 @@ enum class QasmVersion {
QASM2
}

@JsExport
@Serializable
data class Backend(
val id: String? = null,
val name: String
)

@JsExport
@Serializable
data class HubInfo(
val hub: HubInfoName,
val group: HubInfoName,
val project: HubInfoName
)

@JsExport
@Serializable
data class HubInfoName(
val name: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api.models

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@JsExport
@Serializable
data class JobResponse(
val kind: String? = null,
Expand All @@ -28,6 +33,7 @@ data class JobResponse(
val clientInfo: JobClientInfo
)

@JsExport
@Serializable
data class JobSummaryData(
val size: JobSummaryDataSize,
Expand All @@ -36,12 +42,14 @@ data class JobSummaryData(
val resultTime: Double? = null
)

@JsExport
@Serializable
data class JobSummaryDataSize(
val input: Int,
val output: Int? = null
)

@JsExport
@Serializable
data class JobSummaryDataSummary(
@SerialName("qobj_config")
Expand All @@ -56,6 +64,7 @@ data class JobSummaryDataSummary(
val maxQubitsUsed: Int
)

@JsExport
@Serializable
data class JobSummaryDataSummaryQobjConfig(
@SerialName("n_qubits")
Expand All @@ -67,6 +76,7 @@ data class JobSummaryDataSummaryQobjConfig(
val cost: Double
)

@JsExport
@Serializable
data class JobClientInfo(
val name: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
@file:OptIn(ExperimentalJsExport::class)

package net.javaman.brackt.providers.ibmq.api.models

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@JsExport
@Serializable
data class JobsResponse(
val meta: JobsMeta,
val items: List<JobsItem>
)

@JsExport
@Serializable
data class JobsMeta(
val skip: Int,
val limit: Int,
val count: Int
)

@JsExport
@Serializable
data class JobsItem(
val id: String,
Expand All @@ -33,6 +40,7 @@ data class JobsItem(
val infoQueue: JobsItemInfoQueue? = null
)

@JsExport
@Serializable
data class JobsItemProvider(
val hub: String,
Expand All @@ -41,6 +49,7 @@ data class JobsItemProvider(
val backend: String
)

@JsExport
@Serializable
data class JobsItemInfoQueue(
val status: String,
Expand Down
Loading

0 comments on commit 590febe

Please sign in to comment.