diff --git a/README.md b/README.md index 1615e65..3b78e65 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Quantum.js Framework -This repository contains a quantum computing framework implemented in TypeScript. The library provides a `Circuit` class that allows users to create and manipulate quantum circuits using quantum gates. The library also includes static methods to generate random numbers and strings using quantum principles. +This repository contains a quantum computing framework implemented in TypeScript. The library provides a `Circuit` class that allows users to create and manipulate quantum circuits using quantum gates. The library also includes static methods to generate random numbers and strings using quantum principles. Also, it includes a method to optimize the QAOA algorithm using the COBYLA optimization algorithm for the Max-Cut problem. ## [Documentation link](https://docs-quantum-js.iot-sdn.space/) @@ -39,16 +39,26 @@ console.log(result); The library supports the following quantum gates, check the table below for the corresponding methods: -| Gate | Method | -|------|--------| -| Identity (I) | i(qubitIndex: number) | -| Hadamard (H) | h(qubitIndex: number) | -| Pauli-X (X) | x(qubitIndex: number) | -| Pauli-Y (Y) | y(qubitIndex: number) | -| Pauli-Z (Z) | z(qubitIndex: number) | -| T-gate | t(qubitIndex: number) | +| Gate | Method | +| ------------------- | --------------------------------------------- | +| Identity (I) | i(qubitIndex: number) | +| Hadamard (H) | h(qubitIndex: number) | +| Pauli-X (X) | x(qubitIndex: number) | +| Pauli-Y (Y) | y(qubitIndex: number) | +| Pauli-Z (Z) | z(qubitIndex: number) | +| T-gate | t(qubitIndex: number) | | Controlled-X (CNOT) | cx(controlIndex: number, targetIndex: number) | -| Controlled-Z | cz(controlIndex: number, targetIndex: number) | +| Controlled-Z | cz(controlIndex: number, targetIndex: number) | + +## Quantum Functions + +| Functions | Description | +| -------------------------------- | --------------------------------------------------------------------------------------- | +| Circuit.genRandomNumber | Generate a random number using quantum principles | +| Circuit.genRandomString | Generate a random string using quantum principles | +| Circuit.genRandomNumberWithRange | Generate a random number within a specified range using quantum principles | +| Circuit.teleportationOneToTree | Teleportation of a qubit from one quantum register to another | +| optimizeQAOAWithCOBYLA | Optimize the QAOA algorithm using the COBYLA optimization algorithm for Max-Cut problem | ## Dependencies @@ -58,4 +68,3 @@ The library uses the following dependencies: - [quantum-circuit](https://www.npmjs.com/package/quantum-circuit) - For quantum circuit simulation For more information, check the [documentation](https://docs-quantum-js.iot-sdn.space/). - diff --git a/library/circuit.ts b/library/circuit.ts index 505b9b5..6dd7987 100644 --- a/library/circuit.ts +++ b/library/circuit.ts @@ -1,11 +1,6 @@ import QuantumCircuit from 'quantum-circuit'; - -declare module 'quantum-circuit'; - -import { QuantumCircuitInterface } from './types/quantum-circuit'; - export class Circuit { - private quantumCircuit: QuantumCircuitInterface; + private quantumCircuit: QuantumCircuit; constructor(qubitCount: number) { this.quantumCircuit = new QuantumCircuit(qubitCount); diff --git a/library/global.d.ts b/library/global.d.ts index 1285bb1..e82e10a 100644 --- a/library/global.d.ts +++ b/library/global.d.ts @@ -1 +1,400 @@ -declare module 'quantum-circuit'; \ No newline at end of file +declare module 'quantum-circuit' { + export default class QuantumCircuit { + constructor(numQubits?: number); + + MCU1Circuit(ctrlQubits: any): any; + + MCXCircuit(ctrlQubits: any): any; + + addGate(gateName: string, column: number, wires: number | number[], options?: any): any; + + addMeasure(wire: any, creg: any, cbit: any): void; + + angles(): any; + + appendCircuit(circuit: any, pack: any): void; + + appendGate(gateName: any, wires: any, options: any): any; + + appendQubits(numQubits: any): void; + + applyGate(gateName: any, column: any, wires: any, options: any): void; + + applyTransform(U: any, qubits: any): void; + + chanceMap(): any; + + circuitMatrix(endianness: any): any; + + clear(): void; + + clearGates(): void; + + clearPartitions(): void; + + continue(): void; + + convertToCustomGate(gateName: any, decompose: any, addToCircuit: any): void; + + countOps(obj: any, options: any): any; + + countParameterizedGates(): any; + + createCreg(creg: any, len: any): void; + + createPartitions(): void; + + cregBase(creg: any): any; + + cregCount(): any; + + cregTotalBits(): any; + + cregsAsString(): any; + + decodeMultiControlledGateName(gateName: any): any; + + decompose(obj: any): any; + + decomposeGateAt(column: any, wire: any): any; + + defaultHybridOptions(): any; + + densityMatrix(): any; + + eigenvalues2x2(A: any): any; + + eulerAnglesZYZ(inputMatrix: any): any; + + evalMathString(str: any, vars: any): any; + + exportAQASM( + comment: any, + decompose: any, + isExportPyAQASM: any, + exportAsGateName: any, + asJupyter: any, + shots: any, + hybrid: any, + indentDepth: any + ): any; + + exportBraket( + comment: any, + decompose: any, + exportAsGateName: any, + versionStr: any, + asJupyter: any, + shots: any, + hybrid: any, + indentDepth: any + ): any; + + exportCirq( + comment: any, + decompose: any, + exportAsGateName: any, + versionStr: any, + asJupyter: any, + shots: any, + exportTfq: any + ): any; + + exportJavaScript(comment: any, decompose: any, exportAsGateName: any, asJupyter: any): any; + + exportPyAQASM(comment: any, decompose: any, exportAsGateName: any, asJupyter: any, shots: any, hybrid: any): any; + + exportPyquil( + comment: any, + decompose: any, + exportAsGateName: any, + versionStr: any, + lattice: any, + asQVM: any, + asJupyter: any, + shots: any, + hybrid: any + ): any; + + exportQASM( + comment: any, + decompose: any, + exportAsGateName: any, + circuitReplacement: any, + compatibilityMode: any, + insideSubmodule: any + ): any; + + exportQSharp( + comment: any, + decompose: any, + exportAsGateName: any, + versionStr: any, + asJupyter: any, + circuitName: any, + indentDepth?: any + ): any; + + exportQiskit( + comment: any, + decompose: any, + exportAsGateName: any, + versionStr: any, + providerName: any, + backendName: any, + asJupyter: any, + shots: any, + circuitReplacement: any, + insideSubmodule: any, + hybrid: any + ): any; + + exportQobj(circuitName: any, experimentName: any, numShots: any, circuitReplacement: any): any; + + exportQuEST(comment: any, decompose: any, exportAsGateName: any, definedFunc: any): any; + + exportQuil(comment: any, decompose: any, exportAsGateName: any, versionStr: any): any; + + exportQuirk(decompose: any): any; + + exportRaw(): any; + + exportSVG(embedded: any, options?: any): any; + + exportTFQ(comment: any, decompose: any, exportAsGateName: any, versionStr: any, asJupyter: any, shots: any): any; + + exportToAQASM(options: any, isExportPyAQASM: any, exportAsGateName: any, indentDepth: any): any; + + exportToBraket(options: any, exportAsGateName: any): any; + + exportToCirq(options: any, exportAsGateName: any): any; + + exportToGenerator(options: any): any; + + exportToIonq(options: any, circuitReplacement: any): any; + + exportToPyAQASM(options: any, exportAsGateName: any): any; + + exportToPyquil(options: any, exportAsGateName: any): any; + + exportToQASM(options: any, exportAsGateName: any, circuitReplacement: any, insideSubmodule: any): any; + + exportToQSharp(options: any, exportAsGateName: any): any; + + exportToQiskit(options: any, exportAsGateName: any, circuitReplacement: any, insideSubmodule: any): any; + + exportToQobj(options: any, circuitReplacement: any): any; + + exportToQuEST(options: any, exportAsGateName: any, definedFunc: any): any; + + exportToQuil(options: any, exportAsGateName: any): any; + + exportToSVG(options: any): any; + + exportToTFQ(options: any, exportAsGateName: any): any; + + findGlobalParams(): any; + + flipHorizontally(): void; + + flipVertically(): void; + + formatComplex(complex: any, options: any): any; + + getBipartiteState(q1: any, q2: any): any; + + getControllableGatesAtColumn(column: any): any; + + getCouplingMap(options: any): any; + + getCreg(creg: any): any; + + getCregBit(creg: any, cbit: any): any; + + getCregValue(creg: any): any; + + getCregs(): any; + + getGateAt(column: any, wire: any): any; + + getGateBefore(column: any, wire: any): any; + + getGateById(gateId: any): any; + + getGateDef(name: any): any; + + getGatePosById(gateId: any): any; + + getGatesAtColumn(column: any): any; + + getGlobalParams(): any; + + getOrRegisterMultiControlledEquivalent(gateName: any, inverseControl: any): any; + + getRawGate(gate: any, gateOptions: any, globalOptions: any): any; + + gotClassicalControl(): any; + + gotGlobalParams(): any; + + gotMeasurement(): any; + + grayCodeChain(numCtrlQubits: any, gateName: any, gateOptions: any): any; + + importIonq(data: any, errorCallback: any): void; + + importQASM(input: any, errorCallback: any, compatibilityMode: any): void; + + importQobj(qobj: any, errorCallback: any): void; + + importQuil(quil: any, errorCallback: any, options: any, qubitNames: any, renamedGates: any, lineOffset: any): void; + + importRaw(data: any, errorCallback: any): void; + + init(numQubits: any, options: any): void; + + initState(): void; + + insertColumn(colIndex: any): void; + + insertGate(gateName: any, column: any, wires: any, options: any): any; + + insertSpace(column: any, wires: any): any; + + isControllableGate(gateName: any): any; + + isEmptyCell(col: any, wire: any): any; + + isEmptyPlace(col: any, wires: any, usingCregs: any): any; + + isHermitianMatrix(H: any, precision: any): any; + + isIdentityMatrix(m: any, precision: any): any; + + isMultiControlledGate(gateName: any): any; + + isUnitaryMatrix(U: any, precision: any): any; + + lastNonEmptyPlace(wires: any, usingCregs: any): any; + + load(obj: any): void; + + makeAllParamsGlobal(): void; + + matrixAbs(U: any): any; + + matrixArg(U: any): any; + + matrixDiff(matrix1: any, matrix2: any): any; + + matrixHasComplexElement(M: any): any; + + matrixIm(U: any): any; + + matrixRe(U: any): any; + + matrixZeroImagToReal(M: any): any; + + measure(wire: number, creg: string, cbit: number, force?: boolean): any; + + measureAll(force?: any): any; + + measureAllMultishot(shots: any): any; + + minCregSize(creg: any): any; + + multiControlledGateName(namePrefix: any, ctrlQubits: any): any; + + multiplySquareMatrices(m1: any, m2: any): any; + + numAmplitudes(onlyPossible: any): any; + + numCols(): any; + + numGates(decompose: any): any; + + parseMathString(str: any): any; + + parseMatrix(M: any, vars: any): any; + + partialTrace(qubit: any): any; + + partitionBounds(partitionIndex: any): any; + + partitionCircuit(partitionIndex: any): any; + + print(onlyPossible?: boolean): void; + + printPartitions(): void; + + probabilities(): any; + + probability(wire: any): any; + + randomCircuit(numQubits: any, numGates: any, options: any): void; + + randomString(len: any): any; + + randomUnitary(numQubits: any): any; + + registerGate(name: any, obj: any): void; + + registerMCU1Gate(ctrlQubits: any): any; + + registerMCXGate(ctrlQubits: any): any; + + registerMultiControlledGate(rootName: any, ctrlQubits: any): any; + + removeCreg(creg: any): void; + + removeGate(gateId: any): void; + + removeGateAt(column: any, wire: any): void; + + removeLeadingColumns(): void; + + removeMeasurementAndClassicalControl(): void; + + removeQubit(wire: any): void; + + removeTrailingColumns(): void; + + removeTrailingRows(): void; + + removeUnusedMultiControlledGates(): void; + + renameCreg(oldName: any, newName: any): void; + + resetQubit(wire: any, value: any): void; + + resetState(): void; + + resizeCreg(creg: any, size: any): void; + + run(initialValues?: any, options?: any): void; + + save(decompose: any, lightweight: any): any; + + setCombinedState(combineList: any): void; + + setCregBit(creg: any, cbit: any, value: any): void; + + splitIntoBlocks(blockSize: any, options: any): void; + + stateAsArray(onlyPossible: any, skipItems: any, blockSize: any, reverseBits: any): any; + + stateAsSimpleArray(reverseBits: any): any; + + stateAsString(onlyPossible: any): any; + + stringifyMatrix(M: any, options: any): any; + + transformMatrix(totalQubits: any, U: any, targetQubits: any, endianness: any): any; + + updateGlobalParams(): any; + + usedGates(options: any): any; + + validCustomGateName(baseName: any): any; + } +} diff --git a/library/index.ts b/library/index.ts index 3c44a22..425b211 100644 --- a/library/index.ts +++ b/library/index.ts @@ -1,3 +1,4 @@ -import { Circuit } from "./circuit"; +import { Circuit } from './circuit'; +import { optimizeQAOAWithCOBYLA } from './utils'; -export { Circuit }; \ No newline at end of file +export { Circuit, optimizeQAOAWithCOBYLA }; diff --git a/library/types/quantum-circuit.d.ts b/library/types/quantum-circuit.d.ts deleted file mode 100644 index 5e95ef0..0000000 --- a/library/types/quantum-circuit.d.ts +++ /dev/null @@ -1,398 +0,0 @@ -export interface QuantumCircuitInterface { - constructor(numQubits: any): QuantumCircuitInterface; - - MCU1Circuit(ctrlQubits: any): any; - - MCXCircuit(ctrlQubits: any): any; - - addGate(gateName: string, column: number, wires: number | number[], options?: any): any; - - addMeasure(wire: any, creg: any, cbit: any): void; - - angles(): any; - - appendCircuit(circuit: any, pack: any): void; - - appendGate(gateName: any, wires: any, options: any): any; - - appendQubits(numQubits: any): void; - - applyGate(gateName: any, column: any, wires: any, options: any): void; - - applyTransform(U: any, qubits: any): void; - - chanceMap(): any; - - circuitMatrix(endianness: any): any; - - clear(): void; - - clearGates(): void; - - clearPartitions(): void; - - continue(): void; - - convertToCustomGate(gateName: any, decompose: any, addToCircuit: any): void; - - countOps(obj: any, options: any): any; - - countParameterizedGates(): any; - - createCreg(creg: any, len: any): void; - - createPartitions(): void; - - cregBase(creg: any): any; - - cregCount(): any; - - cregTotalBits(): any; - - cregsAsString(): any; - - decodeMultiControlledGateName(gateName: any): any; - - decompose(obj: any): any; - - decomposeGateAt(column: any, wire: any): any; - - defaultHybridOptions(): any; - - densityMatrix(): any; - - eigenvalues2x2(A: any): any; - - eulerAnglesZYZ(inputMatrix: any): any; - - evalMathString(str: any, vars: any): any; - - exportAQASM( - comment: any, - decompose: any, - isExportPyAQASM: any, - exportAsGateName: any, - asJupyter: any, - shots: any, - hybrid: any, - indentDepth: any - ): any; - - exportBraket( - comment: any, - decompose: any, - exportAsGateName: any, - versionStr: any, - asJupyter: any, - shots: any, - hybrid: any, - indentDepth: any - ): any; - - exportCirq( - comment: any, - decompose: any, - exportAsGateName: any, - versionStr: any, - asJupyter: any, - shots: any, - exportTfq: any - ): any; - - exportJavaScript(comment: any, decompose: any, exportAsGateName: any, asJupyter: any): any; - - exportPyAQASM(comment: any, decompose: any, exportAsGateName: any, asJupyter: any, shots: any, hybrid: any): any; - - exportPyquil( - comment: any, - decompose: any, - exportAsGateName: any, - versionStr: any, - lattice: any, - asQVM: any, - asJupyter: any, - shots: any, - hybrid: any - ): any; - - exportQASM( - comment: any, - decompose: any, - exportAsGateName: any, - circuitReplacement: any, - compatibilityMode: any, - insideSubmodule: any - ): any; - - exportQSharp( - comment: any, - decompose: any, - exportAsGateName: any, - versionStr: any, - asJupyter: any, - circuitName: any, - indentDepth?: any - ): any; - - exportQiskit( - comment: any, - decompose: any, - exportAsGateName: any, - versionStr: any, - providerName: any, - backendName: any, - asJupyter: any, - shots: any, - circuitReplacement: any, - insideSubmodule: any, - hybrid: any - ): any; - - exportQobj(circuitName: any, experimentName: any, numShots: any, circuitReplacement: any): any; - - exportQuEST(comment: any, decompose: any, exportAsGateName: any, definedFunc: any): any; - - exportQuil(comment: any, decompose: any, exportAsGateName: any, versionStr: any): any; - - exportQuirk(decompose: any): any; - - exportRaw(): any; - - exportSVG(embedded: any, options?: any): any; - - exportTFQ(comment: any, decompose: any, exportAsGateName: any, versionStr: any, asJupyter: any, shots: any): any; - - exportToAQASM(options: any, isExportPyAQASM: any, exportAsGateName: any, indentDepth: any): any; - - exportToBraket(options: any, exportAsGateName: any): any; - - exportToCirq(options: any, exportAsGateName: any): any; - - exportToGenerator(options: any): any; - - exportToIonq(options: any, circuitReplacement: any): any; - - exportToPyAQASM(options: any, exportAsGateName: any): any; - - exportToPyquil(options: any, exportAsGateName: any): any; - - exportToQASM(options: any, exportAsGateName: any, circuitReplacement: any, insideSubmodule: any): any; - - exportToQSharp(options: any, exportAsGateName: any): any; - - exportToQiskit(options: any, exportAsGateName: any, circuitReplacement: any, insideSubmodule: any): any; - - exportToQobj(options: any, circuitReplacement: any): any; - - exportToQuEST(options: any, exportAsGateName: any, definedFunc: any): any; - - exportToQuil(options: any, exportAsGateName: any): any; - - exportToSVG(options: any): any; - - exportToTFQ(options: any, exportAsGateName: any): any; - - findGlobalParams(): any; - - flipHorizontally(): void; - - flipVertically(): void; - - formatComplex(complex: any, options: any): any; - - getBipartiteState(q1: any, q2: any): any; - - getControllableGatesAtColumn(column: any): any; - - getCouplingMap(options: any): any; - - getCreg(creg: any): any; - - getCregBit(creg: any, cbit: any): any; - - getCregValue(creg: any): any; - - getCregs(): any; - - getGateAt(column: any, wire: any): any; - - getGateBefore(column: any, wire: any): any; - - getGateById(gateId: any): any; - - getGateDef(name: any): any; - - getGatePosById(gateId: any): any; - - getGatesAtColumn(column: any): any; - - getGlobalParams(): any; - - getOrRegisterMultiControlledEquivalent(gateName: any, inverseControl: any): any; - - getRawGate(gate: any, gateOptions: any, globalOptions: any): any; - - gotClassicalControl(): any; - - gotGlobalParams(): any; - - gotMeasurement(): any; - - grayCodeChain(numCtrlQubits: any, gateName: any, gateOptions: any): any; - - importIonq(data: any, errorCallback: any): void; - - importQASM(input: any, errorCallback: any, compatibilityMode: any): void; - - importQobj(qobj: any, errorCallback: any): void; - - importQuil(quil: any, errorCallback: any, options: any, qubitNames: any, renamedGates: any, lineOffset: any): void; - - importRaw(data: any, errorCallback: any): void; - - init(numQubits: any, options: any): void; - - initState(): void; - - insertColumn(colIndex: any): void; - - insertGate(gateName: any, column: any, wires: any, options: any): any; - - insertSpace(column: any, wires: any): any; - - isControllableGate(gateName: any): any; - - isEmptyCell(col: any, wire: any): any; - - isEmptyPlace(col: any, wires: any, usingCregs: any): any; - - isHermitianMatrix(H: any, precision: any): any; - - isIdentityMatrix(m: any, precision: any): any; - - isMultiControlledGate(gateName: any): any; - - isUnitaryMatrix(U: any, precision: any): any; - - lastNonEmptyPlace(wires: any, usingCregs: any): any; - - load(obj: any): void; - - makeAllParamsGlobal(): void; - - matrixAbs(U: any): any; - - matrixArg(U: any): any; - - matrixDiff(matrix1: any, matrix2: any): any; - - matrixHasComplexElement(M: any): any; - - matrixIm(U: any): any; - - matrixRe(U: any): any; - - matrixZeroImagToReal(M: any): any; - - measure(wire: number, creg: string, cbit: number, force?: boolean): any; - - measureAll(force?: any): any; - - measureAllMultishot(shots: any): any; - - minCregSize(creg: any): any; - - multiControlledGateName(namePrefix: any, ctrlQubits: any): any; - - multiplySquareMatrices(m1: any, m2: any): any; - - numAmplitudes(onlyPossible: any): any; - - numCols(): any; - - numGates(decompose: any): any; - - parseMathString(str: any): any; - - parseMatrix(M: any, vars: any): any; - - partialTrace(qubit: any): any; - - partitionBounds(partitionIndex: any): any; - - partitionCircuit(partitionIndex: any): any; - - print(onlyPossible?: boolean): void; - - printPartitions(): void; - - probabilities(): any; - - probability(wire: any): any; - - randomCircuit(numQubits: any, numGates: any, options: any): void; - - randomString(len: any): any; - - randomUnitary(numQubits: any): any; - - registerGate(name: any, obj: any): void; - - registerMCU1Gate(ctrlQubits: any): any; - - registerMCXGate(ctrlQubits: any): any; - - registerMultiControlledGate(rootName: any, ctrlQubits: any): any; - - removeCreg(creg: any): void; - - removeGate(gateId: any): void; - - removeGateAt(column: any, wire: any): void; - - removeLeadingColumns(): void; - - removeMeasurementAndClassicalControl(): void; - - removeQubit(wire: any): void; - - removeTrailingColumns(): void; - - removeTrailingRows(): void; - - removeUnusedMultiControlledGates(): void; - - renameCreg(oldName: any, newName: any): void; - - resetQubit(wire: any, value: any): void; - - resetState(): void; - - resizeCreg(creg: any, size: any): void; - - run(initialValues?: any, options?: any): void; - - save(decompose: any, lightweight: any): any; - - setCombinedState(combineList: any): void; - - setCregBit(creg: any, cbit: any, value: any): void; - - splitIntoBlocks(blockSize: any, options: any): void; - - stateAsArray(onlyPossible: any, skipItems: any, blockSize: any, reverseBits: any): any; - - stateAsSimpleArray(reverseBits: any): any; - - stateAsString(onlyPossible: any): any; - - stringifyMatrix(M: any, options: any): any; - - transformMatrix(totalQubits: any, U: any, targetQubits: any, endianness: any): any; - - updateGlobalParams(): any; - - usedGates(options: any): any; - - validCustomGateName(baseName: any): any; -} diff --git a/library/utils/QAOA/index.ts b/library/utils/QAOA/index.ts index 65bccdd..c373b52 100644 --- a/library/utils/QAOA/index.ts +++ b/library/utils/QAOA/index.ts @@ -28,25 +28,21 @@ function getQAOACircuit( beta: number[], gamma: number[] ): Circuit { - const p = beta.length; // Кількість QAOA кроків + const p = beta.length; const qc = new Circuit(nodes.length); - // Перший крок: застосувати шар Гадамардових воріт nodes.forEach((node) => qc.h(node)); - // Другий крок: застосувати p чергуючих операторів for (let i = 0; i < p; i++) { appendCostOperatorCircuit(qc, edges, gamma[i]); appendMixerOperatorCircuit(qc, nodes, beta[i]); } - // Останній крок: виміряти результат nodes.forEach((node) => qc.measure(node)); return qc; } -// Визначення цільової функції export function objectiveFunction( beta: number[], gamma: number[], @@ -66,11 +62,9 @@ export function objectiveFunction( } const result = qc.measure() as number[]; - // Оцінка результату return computeMaxCutScore(result, edges); } -// Функція для обчислення кількості розрізаних ребер function computeMaxCutScore(result: number[], edges: Array<[number, number]>): number { let score = 0; for (const [i, j] of edges) { @@ -81,28 +75,25 @@ function computeMaxCutScore(result: number[], edges: Array<[number, number]>): n return score; } -// Простий приклад оптимізації COBYLA export function optimizeQAOAWithCOBYLA( nodes: Array, edges: Array<[number, number]>, steps: number, idCircuitDraw?: string ): { beta: number[]; gamma: number[]; score: number; maxCutScore: number } { - let bestBeta: number[] = Array(steps).fill(Math.PI / 4); // Початкове припущення для beta - let bestGamma: number[] = Array(steps).fill(Math.PI / 4); // Початкове припущення для gamma + let bestBeta: number[] = Array(steps).fill(Math.PI / 4); + let bestGamma: number[] = Array(steps).fill(Math.PI / 4); let bestScore = objectiveFunction(bestBeta, bestGamma, nodes, edges, idCircuitDraw); let bestMaxCutScore = bestScore; - const maxIterations = 100; // Максимальна кількість ітерацій - // const tol = 1e-6; // Допустима похибка - const randomStepScale = 0.01; // Масштаб випадкових змін + const maxIterations = 100; + const randomStepScale = 0.01; for (let iter = 0; iter < maxIterations; iter++) { for (let i = 0; i < steps; i++) { const newBeta = [...bestBeta]; const newGamma = [...bestGamma]; - // Зміна значень beta та gamma на невеликий випадковий крок newBeta[i] += (Math.random() - 0.5) * randomStepScale; newGamma[i] += (Math.random() - 0.5) * randomStepScale; diff --git a/library/utils/index.ts b/library/utils/index.ts index e69de29..9d1a051 100644 --- a/library/utils/index.ts +++ b/library/utils/index.ts @@ -0,0 +1,3 @@ +import { optimizeQAOAWithCOBYLA } from './QAOA'; + +export { optimizeQAOAWithCOBYLA }; diff --git a/package-lock.json b/package-lock.json index 1279cff..20cf3ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@earlold/quantum.js", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@earlold/quantum.js", - "version": "0.2.0", + "version": "0.2.1", "license": "ISC", "dependencies": { "mathjs": "^13.0.3", diff --git a/package.json b/package.json index 4cff161..1fc0416 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@earlold/quantum.js", "type": "module", - "version": "0.2.0", + "version": "0.2.1", "description": "Quantum.js is a library for quantum computing", "main": "index.js", "repository": "https://github.com/EarlOld/quantum.js", @@ -23,7 +23,8 @@ "quantum-qubits", "quantum-states", "quantum-superposition", - "qubit" + "qubit", + "QAOA" ], "author": "EarlOd", "license": "ISC", diff --git a/src/index.ts b/src/index.ts index 2fa31a7..9255db2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ -import { optimizeQAOAWithCOBYLA } from 'library/utils/QAOA'; +import { optimizeQAOAWithCOBYLA } from 'library'; -// Приклад використання const nodes = [0, 1, 2, 3, 4]; const edges: Array<[number, number]> = [ [0, 3],