QComplex
A high-performance quantum computing library with WASM acceleration.
Features
- High-performance complex number operations using WebAssembly
- Quantum state vectors with automatic normalization
- Common quantum gates (Hadamard, CNOT, etc.)
- Bell state preparation and manipulation
- Quantum measurements
- Quantum teleportation simulation
- TypeScript support with full type definitions
Installation
npm install @qcomplex/core
Usage
Basic Complex Numbers
import { complexWASM, init } from '@qcomplex/core';
await init();
const z1 = complexWASM.createComplex(1, 2);
const z2 = complexWASM.createComplex(3, -1);
console.log(z1.abs());
console.log(z1.phase());
Quantum States
import { quantum, complexWASM, init } from '@qcomplex/core';
await init();
const state = quantum.createState([
complexWASM.createComplex(1, 0),
complexWASM.createComplex(0, 0)
]);
console.log(state.get_probability(0));
console.log(state.get_probability(1));
Quantum Gates
import { quantum, init } from '@qcomplex/core';
await init();
const state = quantum.utils.create_basis_state(0, 2);
const hadamard = quantum.gates.hadamard();
const superposition = hadamard.apply(state);
const cnot = quantum.gates.cnot();
const entangled = cnot.apply(superposition);
Bell States
import { quantum, init } from '@qcomplex/core';
await init();
const bellState = quantum.utils.create_bell_state(0);
const result = quantum.utils.measure(bellState);
console.log(`Measured: ${result}`);
API Reference
ComplexNumber
real()
: Get real partimag()
: Get imaginary partabs()
: Get magnitudephase()
: Get phase anglescale(factor)
: Scale by real numberadd(other)
: Add complex numbersmultiply(other)
: Multiply complex numbers
QuantumState
get_amplitude(index)
: Get amplitude at indexget_probability(index)
: Get probability at indexdimension()
: Get state space dimensiontensor_product(other)
: Tensor product with another state
QuantumGates
hadamard()
: Create Hadamard gatepauli_x()
: Create Pauli-X (NOT) gatepauli_y()
: Create Pauli-Y gatepauli_z()
: Create Pauli-Z gatecnot()
: Create CNOT gatephase(theta)
: Create phase shift gate
QuantumUtils
create_basis_state(n, dimension)
: Create basis state |n⟩create_bell_state(index)
: Create Bell statemeasure(state)
: Perform measurement
Development
npm install
npm run build
npm test
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.