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

qubitsjs

v1.0.0

Published

A high-performance, sparse-matrix quantum simulator designed for the simulation of NISQ-era (Noisy Intermediate-Scale Quantum) algorithms within a modern JavaScript/Node.js ecosystem.

Readme

qubitsjs

qubitsjs CI

A high-performance, sparse-matrix quantum simulator designed for the simulation of NISQ-era (Noisy Intermediate-Scale Quantum) algorithms within a modern JavaScript/Node.js ecosystem. Unlike traditional simulators that rely on dense state vectors, qubitsjs employs a memory-efficient sparse-map representation and optimized scatter-logic execution to handle high qubit counts with low-to-moderate entanglement.


Installation

npm install qubitsjs

Getting Started

Creating Entanglement (Bell State)

import { Q } from 'qubitsjs';

Q.use(2, (q1, q2, ops) => {
    ops.h(q1);
    ops.cnot(q1, q2);
    
    const m1 = ops.m(q1);
    const m2 = ops.m(q2);
    
    console.log(`Results: q1=${m1}, q2=${m2}`);
    
    ops.reset(q1);
    ops.reset(q2);
});

Classical Control (Iterative Logic)

Q.use(2, (aux, target, ops) => {
    ops.h(aux);
    ops.cnot(aux, target);
    
    const res = ops.m(aux);
    
    ops.if(aux, 1, (subOps) => {
        subOps.x(target);
    });

    ops.reset(aux);
    ops.reset(target);
});

Advanced Noisy Simulation

import { Q, NoiseModel } from 'qubitsjs';

const noise = new NoiseModel({ 
    gateError: 0.01, 
    readoutError: 0.05,
    t1: 0.02,
    t2: 0.01
});

Q.use(1, (q, ops) => {
    ops.h(q);
    console.log(ops.m(q));
    ops.reset(q);
}, noise);

Core Architectural Philosophies

1. Sparse-Matrix State Representation

Traditional simulators represent the quantum state as a dense complex vector of size $2^N$. qubitsjs utilizes a Map-based sparse representation that tracks only non-zero amplitudes. This allows the simulator to maintain a constant memory footprint for basis states and scales with active amplitudes, supporting up to 64 qubits for low-depth circuits.

2. Adaptive Memory Management

To maintain performance during noisy simulations, the simulator employs Adaptive Pruning. If the state Map size exceeds a memory budget (default 5,000 entries), the pruning threshold (base $10^{-15}$) increases dynamically to clear out low-magnitude amplitudes.

3. Scatter-Logic Execution Engine

The engine uses a "Scatter" strategy for gate application, iterating over active states once to update target indices. This approach reduces gate complexity to $O(S)$, where $S$ is the number of non-zero amplitudes.


API Reference

NoiseModel(params)

Defines a comprehensive noise profile including decoherence effects.

  • gateError: Probability of a bit-flip (Pauli-X) after a gate.
  • readoutError: Probability of a measurement result being flipped.
  • t1: Amplitude Damping probability ($|1\rangle \rightarrow |0\rangle$).
  • t2: Phase Damping probability (Pauli-Z flip).

Quantum Operations (ops)

Single-Qubit Gates

  • ops.h(q), ops.x(q), ops.y(q), ops.z(q): Standard Basis Gates.
  • ops.s(q), ops.t(q): Phase and T gates (Essential for universality).
  • ops.rx(q, theta), ops.ry(q, theta), ops.rz(q, theta): Parameterized rotations.
  • ops.u3(q, theta, phi, lambda): Universal unitary gate.

Multi-Qubit & Three-Qubit Gates

  • ops.cnot(ctrl, trgt), ops.cz(ctrl, trgt): Controlled operations.
  • ops.swap(q1, q2): Swaps states of two qubits.
  • ops.rzz(q1, q2, theta): Parameterized ZZ rotation.
  • ops.ccx(c1, c2, t): Toffoli (Controlled-Controlled-NOT) gate.

Classical Control Flow

  • ops.if(qubit, value, callback): Executes the callback if the last measurement of qubit matches value.
  • ops.while(qubit, value, callback): Repeatedly executes the callback while the measurement of qubit matches value.

Algorithms Library

The qubit library includes several pre-built industry-standard algorithms:

  • Search: runGrover(qops, qubits, oracle)
  • Phase Estimation: iterativePhaseEstimation and standard quantumPhaseEstimation
  • Transformations: qft (Quantum Fourier Transform) and inverseQft
  • Oracles: runBernsteinVazirani and runDeutschJozsa
  • Variational: vqeAnsatz and qaoaLayer

Technical Specifications

| Feature | Implementation Detail | |---------|----------------------| | State Storage | Sparse Map: BigUint64Array indices & Float64Array amplitudes | | Compiler Logic | Double-Prune: IR → Optimizer → Transpiler → Optimizer | | Native Basis Set | $U_3$ (Universal Single-Qubit) and $CNOT$ | | Noise Modeling | Bit-flip, Readout, $T_1$ (Amplitude), and $T_2$ (Phase) Damping | | Memory Safety | Mandatory reset to $|0\rangle$ before scope exit |


License

MIT