npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

quantum-circuit-drawer

v1.0.2

Published

A TypeScript library to draw quantum circuits with customizable styles

Readme

Quantum Circuit Drawer

A library for drawing quantum circuits with customizable styles. Ideal for visualizing quantum algorithms and for educational purposes.

Features

  • Comprehensive Gate Support: Includes common quantum gates like Hadamard, Pauli-X, Pauli-Y, Pauli-Z, Rotation gates (Rx, Ry, Rz), CNOT gates, and measurement operations.
  • Customizable Styles: Adjust colors, sizes, fonts, and more to personalize your circuit diagrams.
  • TypeScript Support: Provides type definitions for type safety and IntelliSense support.
  • Browser and Node.js Compatibility: Use the library in both browser environments and Node.js applications.
  • Easy Integration: Simple API design for easy integration into your projects.

Installation

Install the package via npm:

npm install quantum-circuit-drawer

Getting Started

Browser Usage

Include Dependencies:

<!-- Include svg.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/3.2.4/svg.min.js"></script>
<!-- Include the quantum-circuit-drawer library -->
<script src="node_modules/quantum-circuit-drawer/dist/quantum-circuit-drawer.js"></script>

Set Up the HTML Container:

<div id="circuit-container"></div>

Use the Library:

<script>
  const { Circuit, Renderer, HadamardGate, CNOTGate } = QuantumCircuitDrawer;

  const circuit = new Circuit(2);
  circuit.addGate(new HadamardGate(0));
  circuit.addGate(new CNOTGate(0, 1));

  const renderer = new Renderer(circuit, "circuit-container");
  renderer.draw();
</script>

Image

Node.js Usage

Install svg.js:

npm install @svgdotjs/svg.js

Import the Library:

import { SVG } from "@svgdotjs/svg.js";
import {
  Circuit,
  Renderer,
  HadamardGate,
  CNOTGate,
} from "quantum-circuit-drawer";

const circuit = new Circuit(2);
circuit.addGate(new HadamardGate(0));
circuit.addGate(new CNOTGate(0, 1));

const renderer = new Renderer(circuit, "circuit-container");
renderer.draw();

Examples

Basic Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Quantum Circuit Drawer Demo</title>
    <style>
      #circuit-container {
        width: 800px;
        height: 200px;
        border: 1px solid #ccc;
      }
    </style>
  </head>
  <body>
    <div id="circuit-container"></div>
    <!-- Include svg.js -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/3.2.4/svg.min.js"></script>
    <!-- Include the quantum-circuit-drawer library -->
    <script src="node_modules/quantum-circuit-drawer/dist/quantum-circuit-drawer.js"></script>
    <script>
      const { Circuit, Renderer, HadamardGate, CNOTGate } =
        QuantumCircuitDrawer;

      const circuit = new Circuit(2);
      circuit.addGate(new HadamardGate(0));
      circuit.addGate(new CNOTGate(0, 1));

      const renderer = new Renderer(circuit, "circuit-container");
      renderer.draw();
    </script>
  </body>
</html>

Custom Styles

const customStyles = {
  gateFill: "#e0f7fa",
  gateStroke: "#006064",
  fontSize: 16,
  fontFamily: "Courier New, monospace",
  fontColor: "#006064",
  lineColor: "#004d40",
  qubitSpacing: 70,
  gateSpacing: 90,
};

const renderer = new Renderer(circuit, "circuit-container", customStyles);
renderer.draw();

API Reference

Classes

Circuit

Represents a quantum circuit composed of qubits and quantum gates.

Constructor
constructor(numQubits: number)
  • numQubits: The number of qubits in the circuit.
Methods
  • addGate(gate: IGate): Adds a gate to the circuit.
circuit.addGate(new HadamardGate(0));

Renderer

Handles the rendering of the quantum circuit.

Constructor
constructor(
  circuit: Circuit,
  containerId: string,
  styles?: Partial<StyleConfig>
)
  • circuit: The Circuit instance to render.
  • containerId: The ID of the HTML element where the circuit will be drawn.
  • styles: (Optional) Custom styles for the circuit diagram.
Methods
  • draw(): Renders the circuit diagram in the specified container.
const renderer = new Renderer(circuit, "circuit-container", customStyles);
renderer.draw();

Gate Classes

  • HadamardGate
  • CNOTGate
  • PauliXGate
  • PauliYGate
  • PauliZGate
  • RotationGate
  • MeasurementGate

Each gate class implements the IGate interface and represents a specific quantum gate.

circuit.addGate(new PauliXGate(1));
circuit.addGate(new RotationGate("Y", 2, Math.PI / 4));
circuit.addGate(new MeasurementGate(0));

Interfaces

IGate

Represents a generic quantum gate.

interface IGate {
  name: string;
  qubits: number[];
}

StyleConfig

Defines the styling options for the circuit diagram.

Properties:

  • qubitSpacing: Number (default: 50)
  • gateSpacing: Number (default: 70)
  • gateWidth: Number (default: 40)
  • gateHeight: Number (default: 40)
  • lineColor: String (default: '#000')
  • lineWidth: Number (default: 2)
  • gateFill: String (default: '#fff')
  • gateStroke: String (default: '#000')
  • gateStrokeWidth: Number (default: 2)
  • fontSize: Number (default: 14)
  • fontFamily: String (default: 'Arial, sans-serif')
  • fontColor: String (default: '#000')

Example:

const customStyles: Partial<StyleConfig> = {
  gateFill: "#ffe0b2",
  gateStroke: "#ef6c00",
  fontSize: 14,
  fontFamily: "Georgia, serif",
  fontColor: "#ef6c00",
  lineColor: "#bf360c",
  qubitSpacing: 60,
  gateSpacing: 80,
};

License

This project is licensed under the MIT License.