Skip to content

Commit

Permalink
Added super dance coding #4
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlOld committed Aug 10, 2024
1 parent 8bad3a1 commit 6717e13
Show file tree
Hide file tree
Showing 15 changed files with 736 additions and 20 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions docs/pages/examples/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@
},
"quantumTeleportation": {
"title": "Quantum Teleportation"
},
"bellStates": {
"title": "Bell States"
},
"genRandomString": {
"title": "Generate Random String"
},
"superdenseCoding": {
"title": "Superdense Coding"
}
}
53 changes: 53 additions & 0 deletions docs/pages/examples/superdenseCoding.mdx
Original file line number Diff line number Diff line change
@@ -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';

<div style={{background: '#fff'}}>
<Image src="/circuit-1723265269895.webp" alt="Superdense Coding Circuit" width={500} height={300} />
</div>

### 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.
Binary file added docs/public/SDC.webp
Binary file not shown.
Binary file added docs/public/circuit-1723265269895.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config: DocsThemeConfig = {
},
docsRepositoryBase: 'https://github.com/EarlOld/quantum.js',
footer: {
text: 'MIT 2024 © EarlOld - [email protected].2',
text: 'MIT 2024 © EarlOld - [email protected].3',
},
};

Expand Down
2 changes: 1 addition & 1 deletion library/__tests__/qaqo.test.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
27 changes: 27 additions & 0 deletions library/__tests__/superDanseCoding.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
4 changes: 2 additions & 2 deletions library/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Circuit } from './circuit';
import { optimizeQAOAWithCOBYLA } from './utils';
import { optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC } from './utils';

export { Circuit, optimizeQAOAWithCOBYLA };
export { Circuit, optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC };
50 changes: 50 additions & 0 deletions library/utils/SuperDenseCoding/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 2 additions & 1 deletion library/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { optimizeQAOAWithCOBYLA } from './QAOA';
import { sendTwoBitsWithSDC } from './SuperDenseCoding';

export { optimizeQAOAWithCOBYLA };
export { optimizeQAOAWithCOBYLA, sendTwoBitsWithSDC };
Loading

0 comments on commit 6717e13

Please sign in to comment.