Skip to main content

Plot pulse sequences.

Project description

pulsefig: Draw Your Pulse Sequences


Pypi Python 3.7+ License Code style: black CodeFactor Codecov Download Stats Documentation

pulsefig is a Python library designed for easy and intuitive drawing of pulse sequences, commonly used in quantum computing, nuclear magnetic resonance (NMR), and other fields that involve waveform manipulation. The library simplifies the process of visualizing pulse sequences by providing flexible and powerful tools to define, customize, and plot these sequences.

Installation

You can install pulsefig via pip:

pip install pulsefig

For more detailed installation instructions, please refer to the How to install guide.

Quick Start

Basic Usage

Here is a simple example to get you started with pulsefig:

import matplotlib.pyplot as plt

from pulsefig import Element, Line

# Define a line with elements attached
line1 = Line("line1").attach_elements(
    Element(0, 1),
    Element(2, 4),
)

# Define another line
line2 = Line("line2").attach_elements(
    Element(0, 2),
    Element(duration=4, delay=1),
)

# Create a figure and axis
fig, ax = plt.subplots(1, 1)

# Combine the lines into an ensemble and draw
(line1 + line2).draw(ax).config_ax(ax)

This code will generate a plot of two pulse sequences defined by the line1 and line2 objects. You can customize each element, its functions, and styling to create complex and detailed pulse sequence diagrams. basic example

Advanced Example

In the following example, we create a more complex pulse sequence involving multiple lines, Gaussian pulses, and exponential filters:

import matplotlib.pyplot as plt

from pulsefig import Element, Line

reset_line = Line("reset").attach_elements(Element(0, 5).set(xlabel="10μs"))
flux_line = Line("flux").attach_elements(
    flux_rise := Element.ExpFilter(0, 3.75, duration=0.2)
    .set(ylabel=" Δᵩ")
    .update_style(alpha=0.3, data_index=0)
    .sweep_height(start_alpha=0.1)
)

drive_line = Line("drive").attach_elements(
    drive_pi := Element.Gaussian(flux_rise, duration=1).set(subtitle="π")
)
readout_line = Line("readout").attach_elements(Element(drive_pi, duration=1, delay=0.5))

# Combine all lines into an ensemble
ens = drive_line + readout_line + flux_line + reset_line

# Plotting the ensemble
fig, ax1 = plt.subplots(1, 1, figsize=(6, 4))
ens.draw(ax1).config_ax(ax1)

In this advanced example:

  • Reset Line: Represents a reset pulse with a duration of 5 units.
  • Flux Line: Shows an exponential filter rising over time.
  • Drive Line: Contains a Gaussian pulse corresponding to a π rotation.
  • Readout Line: Follows the Gaussian pulse and includes a delay.

This sequence is typical in many quantum computing scenarios, where different pulse shapes and sequences are used to manipulate qubits.

example_2

Custom pulses

You can create a completely custom shapes with pulsefig:

import matplotlib.pyplot as plt
import numpy as np

from pulsefig import Element, Line

fig, ax = plt.subplots(1, 1)

# Define a line with elements attached
line1 = Line("drive").attach_elements(
    Element(0, 1)
    .attach_func(lambda x: np.sin(x * 2 * np.pi), end=0.25)
    .attach_func(lambda x: np.exp(-((x - 0.5) ** 2) / 0.05), start=0.5, end=1)
    .update_style(alpha=0.3, data_index=0)
    .sweep_height(start_alpha=0.1)
    .set(subtitle="pi", xlabel="dt"),
    Element(2, 4)
    .attach_func(lambda x: np.sin(x * 2 * np.pi), end=0.25)
    .attach_func(lambda x: np.exp(-((x - 0.5) ** 2) / 0.05), start=0.5, end=1)
    .update_style(alpha=0.3, data_index=0)
    .sweep_height(start_alpha=0.1),
)

# Define another line
line2 = Line("g_h").attach_elements(
    Element(1, 3)
    .set(alpha=0.3, marker="0")
    .set_subtitle("pi", xpos=0.3)
    .set_ylabel("amp", xpos=0.4, ypos=0.65)
    .set_xlabel("dt", xpos=0.3)
    .attach_func(lambda x: np.sin(x * 2 * np.pi), end=0.25)
    .attach_func(lambda x: np.exp(-((x - 0.5) ** 2) / 0.05), start=0.5, end=1)
    .update_style(alpha=0.3, data_index=0)
    .sweep_height(start_alpha=0.1),
)

# Combine the lines into an ensemble and draw
(line1 + line2).draw(ax).config_ax(ax)

This code will generate a plot of two pulse sequences defined by the line1 and line2 objects. You can customize each element, its functions, and styling to create complex and detailed pulse sequence diagrams.

example_3

Documentation

For more detailed documentation, including additional examples, API reference, and tutorials, please visit the pulsefig Documentation.

Contributing

Contributions are welcome! If you would like to contribute to pulsefig, please take a look at our contributing guide.

License

pulsefig is licensed under the LGPL License. See the LICENSE file for more details.


Feel free to explore the examples, customize the sequences, and integrate pulsefig into your projects for pulse sequence visualization!

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

pulsefig-0.2.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

pulsefig-0.2.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pulsefig-0.2.0.tar.gz.

File metadata

  • Download URL: pulsefig-0.2.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pulsefig-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1080daab8aaf1742f9c22e3291e7f2abec27d4a15549054611fd795ef67a8e98
MD5 8724514659b6d42b3280bfd7a8f930de
BLAKE2b-256 11f35fa9dee9fdbb32c17801dd13c48f8a897ff09993f0778c9101848f67363c

See more details on using hashes here.

File details

Details for the file pulsefig-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pulsefig-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pulsefig-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e462bc119bcf7ef44643e9bbad13c91c40d357f0de9e89dcefbcc25f3e5b3a6d
MD5 e6077377632241bd6f65cb596563a633
BLAKE2b-256 02927319842312abbbcae6fa903417d506c08123dbebcd845f95ba278d30dd65

See more details on using hashes here.

Supported by

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