From 6717e13ecb285d86a5485c056156cc0af5144ab8 Mon Sep 17 00:00:00 2001 From: Sapozhnyk Dmytro Date: Sat, 10 Aug 2024 07:59:33 +0300 Subject: [PATCH] Added super dance coding #4 --- README.md | 13 +- docs/pages/examples/_meta.json | 9 + docs/pages/examples/superdenseCoding.mdx | 53 ++ docs/public/SDC.webp | Bin 0 -> 11446 bytes docs/public/circuit-1723265269895.webp | Bin 0 -> 2656 bytes docs/theme.config.tsx | 2 +- library/__tests__/qaqo.test.ts | 2 +- library/__tests__/superDanseCoding.test.ts | 27 + library/index.ts | 4 +- library/utils/SuperDenseCoding/index.ts | 50 ++ library/utils/index.ts | 3 +- package-lock.json | 571 ++++++++++++++++++++- package.json | 3 +- src/index.ts | 11 +- src/node/circuitToImage.ts | 8 + 15 files changed, 736 insertions(+), 20 deletions(-) create mode 100644 docs/pages/examples/superdenseCoding.mdx create mode 100644 docs/public/SDC.webp create mode 100644 docs/public/circuit-1723265269895.webp create mode 100644 library/__tests__/superDanseCoding.test.ts create mode 100644 library/utils/SuperDenseCoding/index.ts create mode 100644 src/node/circuitToImage.ts diff --git a/README.md b/README.md index 97644f9..8b5b11e 100644 --- a/README.md +++ b/README.md @@ -60,15 +60,14 @@ The library supports the following quantum gates, check the table below for the | 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 | - ## Bell State Functions -| Functions | Description | -| ------------------------ | --------------------------------------------------------------------------- | -| Circuit.prepareBellPhiPlus | Prepare the Bell state Phi+ | -| Circuit.prepareBellPhiMinus | Prepare the Bell state Phi- | -| Circuit.prepareBellPsiPlus | Prepare the Bell state Psi+ | -| Circuit.prepareBellPsiMinus | Prepare the Bell state Psi- | +| Functions | Description | +| --------------------------- | --------------------------- | +| Circuit.prepareBellPhiPlus | Prepare the Bell state Phi+ | +| Circuit.prepareBellPhiMinus | Prepare the Bell state Phi- | +| Circuit.prepareBellPsiPlus | Prepare the Bell state Psi+ | +| Circuit.prepareBellPsiMinus | Prepare the Bell state Psi- | ## Dependencies diff --git a/docs/pages/examples/_meta.json b/docs/pages/examples/_meta.json index e62809c..b7b426e 100644 --- a/docs/pages/examples/_meta.json +++ b/docs/pages/examples/_meta.json @@ -7,5 +7,14 @@ }, "quantumTeleportation": { "title": "Quantum Teleportation" + }, + "bellStates": { + "title": "Bell States" + }, + "genRandomString": { + "title": "Generate Random String" + }, + "superdenseCoding": { + "title": "Superdense Coding" } } diff --git a/docs/pages/examples/superdenseCoding.mdx b/docs/pages/examples/superdenseCoding.mdx new file mode 100644 index 0000000..0a10e42 --- /dev/null +++ b/docs/pages/examples/superdenseCoding.mdx @@ -0,0 +1,53 @@ +# Superdense Coding + +## Overview + +Superdense coding is a quantum communication protocol that enables the transmission of two classical bits of information using a single qubit. This protocol leverages the phenomenon of quantum entanglement, making it one of the most efficient quantum communication techniques. + +In this protocol, two parties, typically referred to as **Alice** and **Bob**, share an entangled qubit pair. By performing specific quantum operations on her qubit, Alice can encode two classical bits of information. She then sends her qubit to Bob, who can decode the information using his entangled qubit. This allows them to effectively communicate two classical bits using only one qubit. + +### How It Works + +1. **Entanglement Creation**: + - Alice and Bob start with a shared entangled qubit pair. This pair is typically in the Bell state `|00 + |11`. + +2. **Encoding by Alice**: + - Alice encodes her two classical bits (\(00\), \(01\), \(10\), or \(11\)) by applying a specific quantum gate to her qubit. The choice of gate (Identity, X, Z, or XZ) depends on the two bits she wants to send. + +3. **Transmission**: + - After encoding, Alice sends her qubit to Bob. + +4. **Decoding by Bob**: + - Bob, now in possession of both qubits, applies a series of quantum operations (specifically, a CNOT gate followed by a Hadamard gate) to decode the original two classical bits. + +### Quantum Circuit + +Below is the quantum circuit representation of the Superdense Coding protocol. This circuit shows how the two classical bits are encoded into a single qubit and how they can be decoded by the receiving party. + +import Image from 'next/image'; + +
+Superdense Coding Circuit +
+ +### Example Usage in TypeScript + +The following example demonstrates how to use the Superdense Coding protocol to send the classical bits "11": + +```typescript +import { sendTwoBitsWithSDC } from '@earlold/quantum.js'; + +const { data } = sendTwoBitsWithSDC('11'); + +console.log(data); // Outputs: 11 +``` + +In this example, `sendTwoBitsWithSDC` is a function that encapsulates the Superdense Coding protocol. It takes the two classical bits as input, encodes them into a qubit, and simulates the decoding process to return the original bits. + +### Conclusion + +Superdense Coding is a powerful example of quantum communication that highlights the potential of quantum protocols to enhance data transmission efficiency. By understanding and implementing this protocol, you can explore the fascinating interplay between classical and quantum information. + +--- + +This version adds more context and explanation to make the documentation clearer and more informative. \ No newline at end of file diff --git a/docs/public/SDC.webp b/docs/public/SDC.webp new file mode 100644 index 0000000000000000000000000000000000000000..c22b45c8b72ac05038da5498b15da78fc6e74f22 GIT binary patch literal 11446 zcmYj%19W9e6Yh!aWRi((+qP{?Y)_ntZQI7go{4SSw(awB@BQC;uh;5bwX3?nuCCSG zyOgEG#j9xn01Yu=MRi3^O;`W`0R5HmKmn#8fG-K*Bn<%IFbK#7p~eR_1L3!2PmwGl zAtoZZmv;9<2sgER_fBV#WH`pFuDRJ5!LT0ib^fUM?6}M|@I~7n`%T||OL4fxX|N7F z@B+LK05#UZ9!TEZ9%{6amaiOqm%9dh$ln2Gd-Yzv=_^ z^ZRqbnWF098MEK1E)9fnQ1NQ{!XnLt!O%8S0+kz~D-t)93bW<%8q{^EP%1=`*K6Ko#hJ z{{8*zjo@A2zN^J|(HHnp^I7_N^tSa%uo7z_kP3_ec6@4Vv%G5DGdyi=cTEEyfC~R$ zZ(-JKtph(dPX!vcZo_dUIoAv2&(nI0xgnONe$lEgAc=IkTCRrfeEV}op}BZzA2%4p zS0)RGBrK|uUE3zDt&*zuATgCdUe_kh{lfMNH@Q(2cE6YvIKYv?Q1a_a(`Ny^whEGj z>}&ykfl-`ZNOxO3rrRqy1V5{2tjow6e8wZ-O;hbrVNwdGYev)sr%yFnj03abct1BR zLhRvouhh~Ufjf_cO#z)(PVSkf>$P19B*7QrSD*A~$7OsrxvrH?_OK=^Ly)R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bY=O z-^Yw@nW=jck}@4n{O7yQ^b=EGz>j9QXq5l%y4GbRhkfG9S;}a~^R}^$SQJOoyZi(n4$%wW0u?KNS0i4eObj=;pojUAE9`omp*T%_ zlhPQ{*9nV=y0C+v6WAxPT=qcp-U!)!S9~dFuQek8rXfWJgqnS$I-nzaW&t(hH>(P^ z%Qg%|qa4CLlQbjRqh+=vyD5lKL7^s}XwIkz-r0aA`oKHMJB}C?lVNh1y17@=$#^Wy zd90Fj=6-COi~1>R0Oc{s`E7$OTFZZi0O&WD z9}N4I!XQ6;>U$MZS7HGm&D@^alZ9m>OW1MF>bi#9<`GvJ9a}FHYZnQ+=buto&y{V`xVV?v3@gi OZW$Hbdd2_%0001=fiB?y literal 0 HcmV?d00001 diff --git a/docs/theme.config.tsx b/docs/theme.config.tsx index 03e9e4a..79b88fb 100644 --- a/docs/theme.config.tsx +++ b/docs/theme.config.tsx @@ -11,7 +11,7 @@ const config: DocsThemeConfig = { }, docsRepositoryBase: 'https://github.com/EarlOld/quantum.js', footer: { - text: 'MIT 2024 © EarlOld - Quantum.js@0.3.2', + text: 'MIT 2024 © EarlOld - Quantum.js@0.3.3', }, }; diff --git a/library/__tests__/qaqo.test.ts b/library/__tests__/qaqo.test.ts index 7e44afe..03baedc 100644 --- a/library/__tests__/qaqo.test.ts +++ b/library/__tests__/qaqo.test.ts @@ -1,7 +1,7 @@ import { optimizeQAOAWithCOBYLA } from '../index'; describe('QAOA', () => { - it('should create a circuit with 3 qubits', () => { + it('should calc', () => { const nodes = [0, 1, 2, 3, 4]; const edges: Array<[number, number]> = [ [0, 3], diff --git a/library/__tests__/superDanseCoding.test.ts b/library/__tests__/superDanseCoding.test.ts new file mode 100644 index 0000000..e611448 --- /dev/null +++ b/library/__tests__/superDanseCoding.test.ts @@ -0,0 +1,27 @@ +import { sendTwoBitsWithSDC } from '../index'; + +describe('SDC', () => { + it('send two qubits: 11 ', () => { + const { data } = sendTwoBitsWithSDC('11'); + + expect(data).toEqual('11'); + }); + + it('send two qubits: 10 ', () => { + const { data } = sendTwoBitsWithSDC('10'); + + expect(data).toEqual('10'); + }); + + it('send two qubits: 01 ', () => { + const { data } = sendTwoBitsWithSDC('01'); + + expect(data).toEqual('01'); + }); + + it('send two qubits: 00 ', () => { + const { data } = sendTwoBitsWithSDC('00'); + + expect(data).toEqual('00'); + }); +}); diff --git a/library/index.ts b/library/index.ts index 425b211..ea0e299 100644 --- a/library/index.ts +++ b/library/index.ts @@ -1,4 +1,4 @@ import { Circuit } from './circuit'; -import { optimizeQAOAWithCOBYLA } from './utils'; +import { optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC } from './utils'; -export { Circuit, optimizeQAOAWithCOBYLA }; +export { Circuit, optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC }; diff --git a/library/utils/SuperDenseCoding/index.ts b/library/utils/SuperDenseCoding/index.ts new file mode 100644 index 0000000..e5ac622 --- /dev/null +++ b/library/utils/SuperDenseCoding/index.ts @@ -0,0 +1,50 @@ +import { Circuit } from '../../circuit'; + +export type SuperDenseCoding = '00' | '01' | '10' | '11'; + +export type SuperDenseCodingResult = { + data: SuperDenseCoding; + circuit: Circuit; +}; + +export const sendTwoBitsWithSDC = (data: SuperDenseCoding): SuperDenseCodingResult => { + // Create a new circuit + const circuit = new Circuit(2); + + // Encode the qubits + circuit.h(0); + circuit.cx(0, 1); + + // Apply the SuperDanceCoding + + switch (data) { + case '00': + break; + case '01': + circuit.x(0); + break; + case '10': + circuit.z(0); + break; + case '11': + circuit.x(0); + circuit.z(0); + break; + } + + // Decode the qubits + + circuit.cx(0, 1); + circuit.h(0); + + circuit.run(); + + // Measure the qubits + + const result = circuit.measure() as number[]; + + return { + data: `${result[0]}${result[1]}` as SuperDenseCoding, + circuit, + }; +}; diff --git a/library/utils/index.ts b/library/utils/index.ts index 9d1a051..01455ec 100644 --- a/library/utils/index.ts +++ b/library/utils/index.ts @@ -1,3 +1,4 @@ import { optimizeQAOAWithCOBYLA } from './QAOA'; +import { sendTwoBitsWithSDC } from './SuperDenseCoding'; -export { optimizeQAOAWithCOBYLA }; +export { optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC }; diff --git a/package-lock.json b/package-lock.json index 9b8f4c1..9841f82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@earlold/quantum.js", - "version": "0.3.2", + "version": "0.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@earlold/quantum.js", - "version": "0.3.2", + "version": "0.3.3", "license": "ISC", "dependencies": { "mathjs": "^13.0.3", @@ -19,6 +19,7 @@ "gulp": "^5.0.0", "jest": "^29.7.0", "prettier": "^3.3.3", + "sharp": "^0.33.4", "ts-jest": "^29.2.2", "ts-node": "^10.9.2", "ts-patch": "^3.2.1", @@ -727,6 +728,16 @@ "node": ">=12" } }, + "node_modules/@emnapi/runtime": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", + "integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==", + "dev": true, + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -1116,6 +1127,456 @@ "node": ">=10.13.0" } }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.4.tgz", + "integrity": "sha512-p0suNqXufJs9t3RqLBO6vvrgr5OhgbWp76s5gTRvdmxmuv9E1rcaqGUsl3l4mKVmXPkTkTErXediAui4x+8PSA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.0.2" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.4.tgz", + "integrity": "sha512-0l7yRObwtTi82Z6ebVI2PnHT8EB2NxBgpK2MiKJZJ7cz32R4lxd001ecMhzzsZig3Yv9oclvqqdV93jo9hy+Dw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.0.2" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.2.tgz", + "integrity": "sha512-tcK/41Rq8IKlSaKRCCAuuY3lDJjQnYIW1UXU1kxcEKrfL8WR7N6+rzNoOxoQRJWTAECuKwgAHnPvqXGN8XfkHA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "macos": ">=11", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.2.tgz", + "integrity": "sha512-Ofw+7oaWa0HiiMiKWqqaZbaYV3/UGL2wAPeLuJTx+9cXpCRdvQhCLG0IH8YGwM0yGWGLpsF4Su9vM1o6aer+Fw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "macos": ">=10.13", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.2.tgz", + "integrity": "sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.2.tgz", + "integrity": "sha512-x7kCt3N00ofFmmkkdshwj3vGPCnmiDh7Gwnd4nUwZln2YjqPxV1NlTyZOvoDWdKQVDL911487HOueBvrpflagw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.2.tgz", + "integrity": "sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.2.tgz", + "integrity": "sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.2.tgz", + "integrity": "sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.2.tgz", + "integrity": "sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.4.tgz", + "integrity": "sha512-RUgBD1c0+gCYZGCCe6mMdTiOFS0Zc/XrN0fYd6hISIKcDUbAW5NtSQW9g/powkrXYm6Vzwd6y+fqmExDuCdHNQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.0.2" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.4.tgz", + "integrity": "sha512-2800clwVg1ZQtxwSoTlHvtm9ObgAax7V6MTAB/hDT945Tfyy3hVkmiHpeLPCKYqYR1Gcmv1uDZ3a4OFwkdBL7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.0.2" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.4.tgz", + "integrity": "sha512-h3RAL3siQoyzSoH36tUeS0PDmb5wINKGYzcLB5C6DIiAn2F3udeFAum+gj8IbA/82+8RGCTn7XW8WTFnqag4tQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.31", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.0.2" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.4.tgz", + "integrity": "sha512-GoR++s0XW9DGVi8SUGQ/U4AeIzLdNjHka6jidVwapQ/JebGVQIpi52OdyxCNVRE++n1FCLzjDovJNozif7w/Aw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.0.2" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.4.tgz", + "integrity": "sha512-nhr1yC3BlVrKDTl6cO12gTpXMl4ITBUZieehFvMntlCXFzH2bvKG76tBL2Y/OqhupZt81pR7R+Q5YhJxW0rGgQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.0.2" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.4.tgz", + "integrity": "sha512-uCPTku0zwqDmZEOi4ILyGdmW76tH7dm8kKlOIV1XC5cLyJ71ENAAqarOHQh0RLfpIpbV5KOpXzdU6XkJtS0daw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.0.2" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.4.tgz", + "integrity": "sha512-Bmmauh4sXUsUqkleQahpdNXKvo+wa1V9KhT2pDA4VJGKwnKMJXiSTGphn0gnJrlooda0QxCtXc6RX1XAU6hMnQ==", + "cpu": [ + "wasm32" + ], + "dev": true, + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.1.1" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.4.tgz", + "integrity": "sha512-99SJ91XzUhYHbx7uhK3+9Lf7+LjwMGQZMDlO/E/YVJ7Nc3lyDFZPGhjwiYdctoH2BOzW9+TnfqcaMKt0jHLdqw==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.4.tgz", + "integrity": "sha512-3QLocdTRVIrFNye5YocZl+KKpYKP+fksi1QhmOArgx7GyhIbQp/WrJRu176jm8IxromS7RIkzMiMINVdBtC8Aw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -2262,6 +2723,19 @@ "integrity": "sha512-lHl4d5/ONEbLlJvaJNtsF/Lz+WvB07u2ycqTYbdrq7UypDXailES4valYb2eWiJFxZlVmpGekfqoxQhzyFdT4Q==", "dev": true }, + "node_modules/color": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", + "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1", + "color-string": "^1.9.0" + }, + "engines": { + "node": ">=12.5.0" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -2280,6 +2754,16 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dev": true, + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, "node_modules/complex.js": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/complex.js/-/complex.js-2.1.1.tgz", @@ -2412,6 +2896,15 @@ "node": ">=0.10.0" } }, + "node_modules/detect-libc": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", + "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -5060,6 +5553,58 @@ "node": ">= 10.13.0" } }, + "node_modules/sharp": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.4.tgz", + "integrity": "sha512-7i/dt5kGl7qR4gwPRD2biwD2/SvBn3O04J77XKFgL2OnZtQw+AG9wnuS/csmu80nPRHLYE9E41fyEiG8nhH6/Q==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "color": "^4.2.3", + "detect-libc": "^2.0.3", + "semver": "^7.6.0" + }, + "engines": { + "libvips": ">=8.15.2", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.33.4", + "@img/sharp-darwin-x64": "0.33.4", + "@img/sharp-libvips-darwin-arm64": "1.0.2", + "@img/sharp-libvips-darwin-x64": "1.0.2", + "@img/sharp-libvips-linux-arm": "1.0.2", + "@img/sharp-libvips-linux-arm64": "1.0.2", + "@img/sharp-libvips-linux-s390x": "1.0.2", + "@img/sharp-libvips-linux-x64": "1.0.2", + "@img/sharp-libvips-linuxmusl-arm64": "1.0.2", + "@img/sharp-libvips-linuxmusl-x64": "1.0.2", + "@img/sharp-linux-arm": "0.33.4", + "@img/sharp-linux-arm64": "0.33.4", + "@img/sharp-linux-s390x": "0.33.4", + "@img/sharp-linux-x64": "0.33.4", + "@img/sharp-linuxmusl-arm64": "0.33.4", + "@img/sharp-linuxmusl-x64": "0.33.4", + "@img/sharp-wasm32": "0.33.4", + "@img/sharp-win32-ia32": "0.33.4", + "@img/sharp-win32-x64": "0.33.4" + } + }, + "node_modules/sharp/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -5087,6 +5632,21 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "node_modules/simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "dev": true, + "dependencies": { + "is-arrayish": "^0.3.1" + } + }, + "node_modules/simple-swizzle/node_modules/is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", + "dev": true + }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -5523,6 +6083,13 @@ "which": "bin/which" } }, + "node_modules/tslib": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", + "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", + "dev": true, + "optional": true + }, "node_modules/tsx": { "version": "4.16.2", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.16.2.tgz", diff --git a/package.json b/package.json index 2327de5..f821f8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@earlold/quantum.js", "type": "module", - "version": "0.3.2", + "version": "0.3.3", "description": "Quantum.js is a library for quantum computing", "main": "index.js", "repository": "https://github.com/EarlOld/quantum.js", @@ -35,6 +35,7 @@ "gulp": "^5.0.0", "jest": "^29.7.0", "prettier": "^3.3.3", + "sharp": "^0.33.4", "ts-jest": "^29.2.2", "ts-node": "^10.9.2", "ts-patch": "^3.2.1", diff --git a/src/index.ts b/src/index.ts index 12f904e..dcf7500 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,8 @@ -import { Circuit } from 'library'; +import { sendTwoBitsWithSDC } from 'library'; +import { circuitToImage } from './node/circuitToImage'; + +const { data, circuit } = sendTwoBitsWithSDC('11'); + +circuitToImage(circuit); -const circuit = new Circuit(2); -circuit.prepareBellPsiMinus(0, 1); -circuit.run(); -console.log(circuit.stateToString()); diff --git a/src/node/circuitToImage.ts b/src/node/circuitToImage.ts new file mode 100644 index 0000000..246bb86 --- /dev/null +++ b/src/node/circuitToImage.ts @@ -0,0 +1,8 @@ +import { Circuit } from 'library'; +import sharp from 'sharp'; + +export const circuitToImage = (circuit: Circuit): void => { + const svg = circuit.exportSVG(); + + sharp(Buffer.from(svg)).toFile(`circuit-${Date.now()}.webp`); +};