forked from GuillermoFidalgo/QKDP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dev-gfidalgo
- Loading branch information
Showing
7 changed files
with
866 additions
and
1,184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# `qcrypto` Showcase\n", | ||
"\n", | ||
"This notebook presents the key features of `qcrypto`, a Python library of the simulation of simple quantum cryptography simulations. The primary classes of this library are `QstateEnt` and `QstateUnEnt`. These classes are used to represent the quantum state of a set of qubits. The former is the most general, being capable of simulating the state of a possiibility entangled set of qubits, whereas the latter can only be used to simulate a system of qubits which are unentangled." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qcrypto.simbasics import QstateEnt, QstateUnEnt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[0.05056588+0.45371015j 0.24549441+0.12567301j 0.7470044 +0.03376755j\n", | ||
" 0.17609874+0.35406553j]" | ||
] | ||
}, | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Entangled set of n qubits\n", | ||
"n = 2\n", | ||
"qstateent = QstateEnt(init_method=\"random\", init_nbqubits=n)\n", | ||
"qstateent" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"array([0, 0])" | ||
] | ||
}, | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"qstateent.measure_all(\"simult\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Unentangled set of n qubits\n", | ||
"n = 2\n", | ||
"# qstateunent = QstateUnEnt(init_method=\"random\", )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"`qcrypto` also provides methods for applying quantum gates to the qubits, giving it the potential to be used to simulate simple quantum circuits. For instance, we can apply the Hadamard gate:\n", | ||
"$$\n", | ||
" H = \\frac{1}{\\sqrt{2}}\\begin{pmatrix}\n", | ||
" 1 & 1 \\\\ 1 & -1\n", | ||
" \\end{pmatrix}\n", | ||
"$$" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build" | |
|
||
[project] | ||
name = "qcrypto" | ||
version = "0.0.1" | ||
version = "1.0.0" | ||
authors = [ | ||
{name = "Roy Cruz", email = "[email protected]"}, | ||
{name = "Guillermo Fidalgo", email = "[email protected]"}, | ||
|
@@ -13,6 +13,15 @@ authors = [ | |
description = "A package for simple quantum cryptography simulations." | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
"numpy" | ||
] | ||
|
||
[project.optional-dependencies] | ||
tests = [ | ||
"pytest", | ||
"coverage" | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/GuillermoFidalgo/QKDP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import numpy as np | ||
import numpy.typing as npt | ||
from typing import Dict | ||
|
||
Pauli: Dict[str, npt.NDArray[np.complex_]] = { | ||
"x": np.array([[0, 1], [1, 0]], dtype=np.complex_), | ||
"y": np.array([[0, -1j], [1j, 0]], dtype=np.complex_), | ||
"z": np.array([[1, 0], [0, -1]], dtype=np.complex_), | ||
} | ||
|
||
H_gate: npt.NDArray[np.complex_] = (1 / np.sqrt(2)) * np.array( | ||
[[1, 1], [1, -1]], dtype=np.complex_ | ||
) | ||
|
||
|
||
def Phase_shift(phase: float) -> npt.NDArray[np.complex_]: | ||
"""Generates a phase shift gate for a given phase. | ||
Args: | ||
phase (float): The phase angle in radians. | ||
Returns: | ||
NDArray: A 2x2 numpy array representing the phase shift gate. | ||
""" | ||
phase_shift_gate = np.array([1, 0], [0, np.e ** (1j * phase)]) | ||
return phase_shift_gate | ||
|
||
|
||
def tensor_power(gate: npt.NDArray[np.complex_], N: int) -> npt.NDArray[np.complex_]: | ||
"""Computes the tensor power of a 2x2 gate matrix. | ||
Args: | ||
gate (NDArray): A 2x2 numpy array representing a quantum gate. | ||
N (int): The power to which the gate matrix is to be raised, tensor-wise. | ||
Returns: | ||
NDArray: A numpy array representing the N-th tensor power of the gate. | ||
""" | ||
result = gate | ||
for _ in range(N - 1): | ||
result = np.kron(result, gate) | ||
return result |
Oops, something went wrong.