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

jsquil

v2.1.1

Published

Replace pyQuil library with NodeJS

Downloads

21

Readme

jsquil

Greenkeeper badge

JavaScript interface for writing Quil programs, based on Rigetti Computing's pyQuil package.

Make a list of instructions to run on a hybrid computer with both qubits and classical registers, and then use the measure instruction to store a qubit value onto a classical register.

You can then return the value of these classical registers on each run of your program.

Want more JS and Quantum Computers?

Upgrade to Quantum Peep

Multi-platform, async quantum computing library written in TypeScript

Sample code

Tests based on the example code in pyQuil

import { gates, inits, operations, Program, QVM, Connection } from 'jsquil'

// request API credentials from http://rigetti.com/forest
let c = new Connection({
  user_id: 'USER_ID',
  api_key: 'API_KEY'
});

// connection for QVM Docker container (which I host)
let c2 = new Connection({
  user_id: 'USER_ID',
  api_key: 'API_KEY'
}, 'http://165.227.62.245:5000');

let q = new QVM(c2);

let p = new Program();
// put an X gate on the zeroth qubit
p.inst(gates.X(0));

// store the zeroth qubit's value in the first classical register
p.measure(0, 1);

// p now contains Quil instructions, which look like this:
// p.code()
// >  DECLARE ro BIT[2]
// >  X 0
// >  MEASURE 0 ro[1]

// run the program twice, returning classical registers from each iteration
q.run(p, 2, (err, returns) => {
  // err = null
  // returns = [[1], [1]]
});

Changing the run command to execute a program ten times:

q.run(p, 10, (err, returns) => { });

Two ways to write a series of gate commands:

p.inst(gates.X(0), gates.Y(1), gates.Z(0));
// same as
p.inst(gates.X(0));
p.inst(gates.Y(1));
p.inst(gates.Z(0));

p.code();
> "X 0\nY 1\nZ 0\n"

Quantum Fourier Transform:

p.inst(
  gates.H(2),
  gates.CPHASE(Math.PI / 2, 1, 2),
  gates.H(1),
  gates.CPHASE(Math.PI / 4, 0, 2),
  gates.CPHASE(Math.PI / 2, 0, 1),
  gates.H(0),
  gates.SWAP(0, 2)
);

Initializing a classical register value

p.inst( inits.TRUE(0) );

Operations on classical registers

p.inst(operations.EXCHANGE(0, 1));
// others: NOT, AND, OR, MOVE

Reset, wait, and halt commands:

p.reset();
p.wait();
p.halt();

Looping some instructions while a classical register value is TRUE

let classical_register = 2;
let loop_program = new Program();
loop_program.inst(gates.X(0), gates.H(0));
loop_program.measure(0, classical_register);
p.while_do(classical_register, loop_program);

An if-then-else statement combines multiple program objects and chooses one based on a classical register bit value

let then_branch = new Program();
...
let else_branch = new Program();
...
p.if_then(test_register, then_branch, else_branch);

Adding gate and measurement noise to the QVM, to simulate a quantum computer

let gate_noise = [x, y, z];
let measure_noise = [0.2, 0, 0];
let q = new QVM(connection, gate_noise, measure_noise);

Endpoints

If the endpoint changes:

let c = new Connection({
  user_id: 'USER_ID',
  api_key: 'API_KEY'
}, 'https://endpoint.example.com');

Tests

npm install mocha -g
npm test

License

Apache license (same as pyQuil)