Skip to main content

A Python library for quantum state manipulations and quantum gates

Project description

qtypi

qtypi is a Python library for performing quantum computations using linear algebra. It provides tools to create and manipulate quantum states and apply quantum gates.

Table of Contents

Installation

You can install qtypi using pip:

pip install qtypi

Creating Quantum States

To create a quantum state, instantiate the QuantumState class by passing a state vector (as a list or numpy array).

from qtypi.quantum_state import QuantumState

# Create the |0> state
state_zero = QuantumState([1, 0])

# Create the |1> state
state_one = QuantumState([0, 1])

Applying Quantum Gates

Quantum gates can be applied to quantum states using the apply_gate method of the QuantumState class. The library includes commonly used gates, such as Hadamard, Pauli-X, Pauli-Y, Pauli-Z, Phase, and CNOT gates.

from qtypi.quantum_gates import QuantumGate

# Create a Hadamard gate
hadamard_gate = QuantumGate.hadamard()

# Apply the Hadamard gate to the |0> state
new_state = state_zero.apply_gate(hadamard_gate)

print(new_state)

Available Quantum Gates

The following gates are available as static methods in the QuantumGate class:

  • Hadamard Gate: QuantumGate.hadamard()
  • Pauli-X Gate: QuantumGate.pauli_x()
  • Pauli-Y Gate: QuantumGate.pauli_y()
  • Pauli-Z Gate: QuantumGate.pauli_z()
  • Phase Gate: QuantumGate.phase(theta)
  • CNOT Gate: QuantumGate.cnot()
  • Custom Gate: QuantumGate.custom_gate(matrix)

Example Usage

Creating and Applying Gates

Here’s a complete example of creating a quantum state, applying a Hadamard gate, and printing the result:

from qtypi.quantum_state import QuantumState
from qtypi.quantum_gates import QuantumGate

# Initialize the |0> state
state = QuantumState([1, 0])

# Create a Hadamard gate
hadamard_gate = QuantumGate.hadamard()

# Apply the Hadamard gate to the |0> state
new_state = state.apply_gate(hadamard_gate)

# Print the resulting quantum state
print("New State after applying Hadamard:", new_state)

Custom Quantum Gates

You can create and apply custom quantum gates using a matrix of your choice. For example:

import numpy as np
from qtypi.quantum_state import QuantumState
from qtypi.quantum_gates import QuantumGate

# Define a custom matrix
custom_matrix = np.array([[0, 1], [1, 0]])  # Equivalent to Pauli-X gate

# Create the custom gate
custom_gate = QuantumGate.custom_gate(custom_matrix)

# Apply it to a |0> state
state = QuantumState([1, 0])
new_state = state.apply_gate(custom_gate)

print("New State after applying custom gate:", new_state)

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtypi-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qtypi-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file qtypi-0.1.0.tar.gz.

File metadata

  • Download URL: qtypi-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for qtypi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb0514048a0ffb652636adcb8ab716117369cba7f0c5688ed52f86e5a0dfd7ad
MD5 c53bc1a06edb8326d4f21d3e3f56d4df
BLAKE2b-256 268b6d27c32fe267d70c613e8a098f4930f2c44ea1b4ad591be34b2e4dd6e472

See more details on using hashes here.

File details

Details for the file qtypi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qtypi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for qtypi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af833815c6b60c3162716f2d7a0b1a33982be8ad78c4b4f3d5ed4c2e5a37067b
MD5 1485db708fbe0d158e8fea1e2473d0a2
BLAKE2b-256 e3028750ff2ea4c08b8e59b951cb30a2d69d628caae5212ee4d81c8dc90c8011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page