jsquil
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?
Quantum Peep
Upgrade toMulti-platform, async quantum computing library written in TypeScript
Sample code
Tests based on the example code in pyQuil
// request API credentials from http://rigetti.com/forestlet c = user_id: 'USER_ID' api_key: 'API_KEY'; // connection for QVM Docker container (which I host)let c2 = user_id: 'USER_ID' api_key: 'API_KEY' 'http://165.227.62.245:5000'; let q = c2; let p = ;// put an X gate on the zeroth qubitp; // store the zeroth qubit's value in the first classical registerp; // 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 iterationq;
Changing the run command to execute a program ten times:
q;
Two ways to write a series of gate commands:
p;// same asp;p;p; pcode;> "X 0\nY 1\nZ 0\n"
p;
Initializing a classical register value
p;
Operations on classical registers
p;// others: NOT, AND, OR, MOVE
Reset, wait, and halt commands:
p;p;p;
Looping some instructions while a classical register value is TRUE
let classical_register = 2;let loop_program = ;loop_program;loop_program;p;
An if-then-else statement combines multiple program objects and chooses one based on a classical register bit value
let then_branch = ;...let else_branch = ;...p;
Adding gate and measurement noise to the QVM, to simulate a quantum computer
let gate_noise = x y z;let measure_noise = 02 0 0;let q = connection gate_noise measure_noise;
Endpoints
If the endpoint changes:
let c = user_id: 'USER_ID' api_key: 'API_KEY' 'https://endpoint.example.com';
Tests
npm install mocha -gnpm test
License
Apache license (same as pyQuil)