{"id":13776599,"url":"https://github.com/mapmeld/jsquil","last_synced_at":"2025-04-12T19:02:50.117Z","repository":{"id":57159867,"uuid":"84122792","full_name":"mapmeld/jsquil","owner":"mapmeld","description":"Quantum computer instructions for JavaScript developers","archived":false,"fork":false,"pushed_at":"2020-06-24T23:24:11.000Z","size":38,"stargazers_count":50,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-11T18:07:45.975Z","etag":null,"topics":["quantum-computing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mapmeld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-06T21:30:32.000Z","updated_at":"2024-04-16T10:59:31.000Z","dependencies_parsed_at":"2022-09-09T00:02:31.750Z","dependency_job_id":null,"html_url":"https://github.com/mapmeld/jsquil","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapmeld%2Fjsquil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapmeld%2Fjsquil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapmeld%2Fjsquil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapmeld%2Fjsquil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mapmeld","download_url":"https://codeload.github.com/mapmeld/jsquil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224742396,"owners_count":17362232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["quantum-computing"],"created_at":"2024-08-03T18:00:29.903Z","updated_at":"2024-11-15T07:14:14.668Z","avatar_url":"https://github.com/mapmeld.png","language":"JavaScript","funding_links":[],"categories":["Quantum simulators"],"sub_categories":[],"readme":"# jsquil\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/mapmeld/jsquil.svg)](https://greenkeeper.io/)\n\nJavaScript interface for writing Quil programs, based on Rigetti Computing's\n\u003ca href='https://github.com/rigetticomputing/pyquil'\u003epyQuil package\u003c/a\u003e.\n\nMake a list of instructions to run on a hybrid computer with both qubits and classical registers, and then use the\nmeasure instruction to store a qubit value onto a classical register.\n\nYou can then return the value of these classical registers on each run of your program.\n\n# Want more JS and Quantum Computers?\n## Upgrade to \u003ca href=\"https://github.com/mapmeld/quantum-peep\"\u003eQuantum Peep\u003c/a\u003e\nMulti-platform, async quantum computing library written in TypeScript\n\n## Sample code\n\nTests based on the example code in pyQuil\n\n```javascript\nimport { gates, inits, operations, Program, QVM, Connection } from 'jsquil'\n\n// request API credentials from http://rigetti.com/forest\nlet c = new Connection({\n  user_id: 'USER_ID',\n  api_key: 'API_KEY'\n});\n\n// connection for QVM Docker container (which I host)\nlet c2 = new Connection({\n  user_id: 'USER_ID',\n  api_key: 'API_KEY'\n}, 'http://165.227.62.245:5000');\n\nlet q = new QVM(c2);\n\nlet p = new Program();\n// put an X gate on the zeroth qubit\np.inst(gates.X(0));\n\n// store the zeroth qubit's value in the first classical register\np.measure(0, 1);\n\n// p now contains Quil instructions, which look like this:\n// p.code()\n// \u003e  DECLARE ro BIT[2]\n// \u003e  X 0\n// \u003e  MEASURE 0 ro[1]\n\n// run the program twice, returning classical registers from each iteration\nq.run(p, 2, (err, returns) =\u003e {\n  // err = null\n  // returns = [[1], [1]]\n});\n```\n\nChanging the run command to execute a program ten times:\n\n```javascript\nq.run(p, 10, (err, returns) =\u003e { });\n```\n\nTwo ways to write a series of gate commands:\n\n```javascript\np.inst(gates.X(0), gates.Y(1), gates.Z(0));\n// same as\np.inst(gates.X(0));\np.inst(gates.Y(1));\np.inst(gates.Z(0));\n\np.code();\n\u003e \"X 0\\nY 1\\nZ 0\\n\"\n```\n\n\u003ca href='https://en.wikipedia.org/wiki/Quantum_Fourier_transform'\u003eQuantum Fourier Transform\u003c/a\u003e:\n\n```javascript\np.inst(\n  gates.H(2),\n  gates.CPHASE(Math.PI / 2, 1, 2),\n  gates.H(1),\n  gates.CPHASE(Math.PI / 4, 0, 2),\n  gates.CPHASE(Math.PI / 2, 0, 1),\n  gates.H(0),\n  gates.SWAP(0, 2)\n);\n```\n\nInitializing a classical register value\n\n```javascript\np.inst( inits.TRUE(0) );\n```\n\nOperations on classical registers\n\n```javascript\np.inst(operations.EXCHANGE(0, 1));\n// others: NOT, AND, OR, MOVE\n```\n\nReset, wait, and halt commands:\n\n```javascript\np.reset();\np.wait();\np.halt();\n```\n\nLooping some instructions while a classical register value is TRUE\n\n```javascript\nlet classical_register = 2;\nlet loop_program = new Program();\nloop_program.inst(gates.X(0), gates.H(0));\nloop_program.measure(0, classical_register);\np.while_do(classical_register, loop_program);\n```\n\nAn if-then-else statement combines multiple program objects and chooses one based on a classical register bit value\n\n```javascript\nlet then_branch = new Program();\n...\nlet else_branch = new Program();\n...\np.if_then(test_register, then_branch, else_branch);\n```\n\nAdding gate and measurement noise to the QVM, to simulate a quantum computer\n\n```javascript\nlet gate_noise = [x, y, z];\nlet measure_noise = [0.2, 0, 0];\nlet q = new QVM(connection, gate_noise, measure_noise);\n```\n\n### Endpoints\n\nIf the endpoint changes:\n\n```javascript\nlet c = new Connection({\n  user_id: 'USER_ID',\n  api_key: 'API_KEY'\n}, 'https://endpoint.example.com');\n```\n\n## Tests\n\n```bash\nnpm install mocha -g\nnpm test\n```\n\n## License\n\nApache license (same as pyQuil)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapmeld%2Fjsquil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapmeld%2Fjsquil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapmeld%2Fjsquil/lists"}