# jsqubits
Quantum computation simulation JavaScript library
[![Build Status](https://github.com/davidbkemp/jsqubits/actions/workflows/node.js.yml/badge.svg)](https://github.com/davidbkemp/jsqubits/actions/workflows/node.js.yml)
Website:
https://davidbkemp.github.io/jsqubits/
The user manual:
https://davidbkemp.github.io/jsqubits/jsqubitsManual.html
Try it out online using the jsqubits runner:
https://davidbkemp.github.io/jsqubits/jsqubitsRunner.html
Wiki (with examples):
https://github.com/davidbkemp/jsqubits/wiki
GitHub:
https://github.com/davidbkemp/jsqubits
Node npm module:
https://npmjs.org/package/jsqubits
You can use it to implement quantum algorithms using JavaScript like this:
jsqubits('|01>')
.hadamard(jsqubits.ALL)
.cnot(1, 0)
.hadamard(jsqubits.ALL)
.measure(1)
.result
If you are new to quantum programming, then it is highly recommended that you try reading
[John Watrous' Quantum Information and Computation Lecture Notes](https://cs.uwaterloo.ca/~watrous/QC-notes/).
You may also wish to try reading the (work in progress) [Introduction to Quantum Programming using jsqubits](https://davidbkemp.github.io/jsqubits/jsqubitsTutorial.html).
Usage
-----
## Online
Try it out online using the jsqubits runner:
https://davidbkemp.github.io/jsqubits/jsqubitsRunner.html
## Install using npm
You can use jsqubits in a Node application by installing jsqubits using npm.
**First, make sure you have at least version 16 of Node installed.**
Place the following code in `myprogram.mjs`.
Note the `.mjs` extension is a way of informing Node that the program uses ES modules.
```javascript
import {jsqubits} from 'jsqubits'
const result = jsqubits('|0101>').hadamard(jsqubits.ALL);
console.log(result.toString());
```
Run the following:
```shell
$ npm install jsqubits@2
$ node myprogram.mjs
```
## Downloading from github
You could use jsqubits by cloning the github repository, or downloading a release from github.
**First, make sure you have at least version 16 of Node installed.**
Clone jsqubits
```shell
$ git clone https://github.com/davidbkemp/jsqubits.git
```
Place the following code in `myprogram.mjs`.
Note the `.mjs` extension is a way of informing Node that the program uses ES modules.
```javascript
import {jsqubits} from './jsqubits/lib/index.js'
const result = jsqubits('|0101>').hadamard(jsqubits.ALL);
console.log(result.toString());
```
Run your program using Node:
```shell
$ node myprogram.mjs
```
## On your own website
We are using [native ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules).
Sadly, this complicates things when using jsqubits from within a web page:
- The page will need to be served by a web server, not just loaded from your local file system.
Note: placing your web page on github pages is an option for this.
- You will need a copy of the contents of the `lib` directory on your web server.
- Your page will need to specify `type="module"` in the `script` tag used to load the jsqubits library.
- The page will not work on old versions of web browsers. It definitely won't work on Internet Explorer.
I have successfully had jsqubits running on Chrome 89, Firefox 87, Safari 14, and Edge 89.
e.g. assuming you have placed the contents of `lib` in a directory called `jsqubits` that sits next to your webpage,
then you could create a simple web page like this:
```html
<html>
<body><p id="result"></p></body>
<script type="module">
import jsqubits from './jsqubits/index.js';
const qstate = jsqubits('|0>').hadamard(0).T(0);
document.getElementById("result").innerHTML = qstate.toString();
</script>
</html>
```
See other examples in the `examples` directory.
TypeScript type definitions
---------------------------
TypeScript type definitions for jsqubits are available:
- Node npm module: https://www.npmjs.com/package/@types/jsqubits
- Github: https://github.com/qramana/jsqubits.d.ts
Development
-----------
To run the tests, you will need to install version 16 or later of Node.js (https://nodejs.org).
Then use `npm install` to install the testing dependencies and `npm test` to run the specs.
NOTE: The tests include an example of factoring using Shor's faction algorithm. This is non-deterministic and can take a fraction of a second or several seconds to complete.
License
-------
(The MIT License)
Copyright (c) 2012 David Kemp <davidbkemp@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
快撑死的鱼
- 粉丝: 2w+
- 资源: 9156
最新资源
- 流水线贴膜机完成项目程序,包含PLC程序和触摸屏程序,程序内 包含上下气缸控制,夹紧气缸控制,输送带电机控制,贴膜伺服控制,旋转电机控制等类容,非常适合学习简单控制工艺及运动控制初学者学习,该程序支持
- PLC与变频器RS指令无协议通讯 适应支持MODBUS.RTU模式的各品牌变频器 RS485ADP或者RS485BD板都可以 本程序编写了CRC循环冗余校验码程序,针对FX1N.2N没有CRC专
- 自己封装的爱普生机器人与三菱的MC协议通信驱动程序,提供项目源码、MC协议源码,需要一定基础(通信 MC协议 爱普生机器人编程)才能调的通
- 紧急道,紧急避障,横纵向联合控制,模型预测控制+pid控制方案,通过控制转角以及车轮力矩实现道,避障轨迹 matlab用的是2016,carsim用的是2018
- 基于plc智能停车场车位控制仿真 功能介绍: ①假设某停车场共有16个车位 ②在停车场入口处装设有一传感器,用来检测车辆进入的数目 ③在停车场出口处装设有一传感器,用来检测车辆出去的数目 ④尚有
- 能量和储备调度的分布鲁棒联合机会约束 测试环境:MATLAB 关键词:分布式鲁棒优化,能量和储备调度,联合机会约束 我们开发了一个两阶段的随机计划,为能源和储备调度的联合电力和天然气系统的高渗透的可再
- 插电式混合动力汽车的能量管理:模型预测控制的凸优化算法 测试环境:MATLAB 关键词:乘法器交替方向法、能量管理、内点法、模型预测控制、插电式混合动力汽车 求解非线性损耗混合动力汽车能量管理模型预测
- 储能参与调频调峰联合优化运行 关键词:储能 调频 调峰 储能优化 联合优化 测试环境:matlab平台 通过一个联合优化框架同时使用电池存储系统进行调峰和频率调节,该框架可以捕捉到电池 化、操作限
- 基于最小二乘法和快速解耦法的电网状态估计 测试环境:MATLAB 电网状态估计问题的实质是当方程的个数大于变量的个数时,对方程变量进行无偏估计 对于电网系统,变量为节点电压(即状态值,由实部和虚部
- 四轮轮毂电机驱动车辆,驱动电机故障状态估计(UKF) 软件使用:Matlab Simulink 适用场景:采用无迹卡尔曼滤波UKF进行轮毂电机状态估计,失效电机估计状态为0,正常电机状态为1 产品
- 汇川H3UCAN总线高性能PLC实机程序,本体应用五轴?CAN总线轴控两轴SV630总线伺服电机,最大可扩充16轴运动总线 另外一路MODBUS总线控制高频温控器 配合台湾威纶通TK6071IP触
- 倒立摆源码 13年国赛电赛旋转倒立摆 完整全功能 程序 倒立摆 pid算法 程序使用时可根据硬件需要自行调节 基本要求 1. 摆杆从处于自然下垂状态(摆角 0°)开始,驱动电机带动旋转臂作往复旋转使
- 成熟 步进电机驱动 方案 全套
- 考虑电动汽车调度潜力的两阶段充电桩市场投标 代码 测试环境:MATLAB 关键词:电动汽车,车并网,纳什均衡,投标策略 充电站投标优化能降低电力成本甚至通过电取益 考虑了电动汽车成为柔性储荷资源的
- 四相8 6极开关磁阻电机maxwell仿真资料
- labview串口,网口,DSC可用OPC通讯链接三菱欧姆龙西门子等PLC 需要的取,可帮助使用 通过NI-OPC控制三菱,欧姆龙西门子等各种型号PLC
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈