Skip to main content

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!

Metadata

Release files for pulsefig 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pulsefig 0.2.0
File Size Uploaded Provenance
pulsefig-0.2.0.tar.gz 15.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pulsefig 0.2.0
File Interpreter ABI Platform
pulsefig-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.0 kB

Release files / pulsefig-0.2.0.tar.gz

Download URL pulsefig-0.2.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1080daab8aaf1742f9c22e3291e7f2abec27d4a15549054611fd795ef67a8e98
BLAKE2b-256 checksum
How to use checksums
11f35fa9dee9fdbb32c17801dd13c48f8a897ff09993f0778c9101848f67363c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / pulsefig-0.2.0-py3-none-any.whl

Download URL pulsefig-0.2.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e462bc119bcf7ef44643e9bbad13c91c40d357f0de9e89dcefbcc25f3e5b3a6d
BLAKE2b-256 checksum
How to use checksums
02927319842312abbbcae6fa903417d506c08123dbebcd845f95ba278d30dd65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for pulsefig 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page