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 🙏

© 2024 – Pkg Stats / Ryan Hefner

qulacs-wasm

v0.0.5

Published

Qulacs WebAssembly version

Downloads

4

Readme

Qulacs Wasm

qulacs-wasm lets you use Qulacs in JavaScript via WebAssembly. It provides a convenient syntax similar to Qulacs on Python in JavaScript/TypeScript, and aims an efficient way to manipulate quantum computation on JavaScript runtime environment.

Qulacs and qulacs-wasm is licensed under the MIT license.

Usage

npm install qulacs-wasm
import { initQulacs } from "qulacs-wasm";

initQulacs()
  .then(async () => {
    const { QuantumState, QuantumCircuit } = await import("qulacs-wasm");
    const qubitCount = 2;
    const state = new QuantumState(qubitCount);
    state.set_zero_state();
    const circuit = new QuantumCircuit(qubitCount);
    circuit.add_H_gate(0);
    circuit.add_CNOT_gate(0, 1);
    circuit.update_quantum_state(state);
    console.log("state vector ", state.get_vector());
    console.log("sampling", state.sampling(10)); // sampling may return 0th/3th base state with equal probability
  });
state vector [
  { real: 0.7071067811865475, imag: 0 },
  { real: 0, imag: 0 },
  { real: 0, imag: 0 },
  { real: 0.7071067811865475, imag: 0 }
]
sampling [
  0, 0, 3, 3, 3,
  0, 0, 0, 0, 0
]

Features

  • Almost fully Qulacs on Python compatible interface (except for direct json file access)
  • Very fast quantum circuit simulation in JavaScript environments
  • Provides TypeScript d.ts
  • Support for external loading of .wasm file

Qulacs Python Advanced Guide use case is implemented by TypeScript in advanced-guide.test.ts.

Performance

The time to simulate a random quantum circuit is compared to the original Qulacs(November 2020).

This benchmark test complies with benchmark-qulacs and you can see the detail here.

Single-thread benchmark

single thread benchmark

How to import from external .wasm file

qulacs-wasm automatically loads bundled wasm binary, but can also load it externally. This helps manage js bundle size.

import { initQulacs } from "qulacs-wasm/lib/nobundle";

const module = await WebAssembly.compile(fs.readFileSync("../path/to/module.wasm")); // Node.js
// const module = await WebAssembly.compileStreaming(fetch("module.wasm")); // online
await initQulacs({ module });
const { QuantumState, X } = await import("qulacs-wasm/lib/nobundle");
const state = new QuantumState(1);
(X(0)).update_quantum_state(state);

How to include .wasm file for your project, details in sample.

Build qulacs-wasm from source

Building qulacs-wasm involves building Qulacs and Boost, so those requirements must be satisfied, and Emscripten environment for qulacs-wasm.

Requirements

  • Qulacs requirements (tested on v0.5.6)
  • Emscripten (tested on v3.1.22)
    • need em++ command
  • Node.js/npm (tested on Node.js v18.3.0/npm 8.11.0)
    • some version included in Emscripten environment

tested on the following systems.

  • Ubuntu 20.04.3 LTS (on WSL2)
npm run init
npm run submodule:build
npm install
npm run build

Non-available classes and functions

  • [ ] GPU class (ex: QuantumStateGpu)
  • [ ] ITYPE(long long int) type (automatically cast to int)
  • [ ] file access functions (ex: create_quantum_operator_from_openfermion_file / create_observable_from_openfermion_file / create_split_quantum_operator)
  • [ ] Multi-thread (limited by currently WebAssembly Specifications)

Pull Requests Welcome!