Package: tensorcircuit-nightly
English |简体中文TensorCircuit is the next generation of quantum software framework with support for automatic differentiation, just-in-time compiling, hardware acceleration, and vectorized parallelism.TensorCircuit is built on top of modern machine learning frameworks: Jax, TensorFlow, and PyTorch. It is specifically suitable for highly efficient simulations of quantum-classical hybrid paradigm and variational quantum algorithms in ideal, noisy and approximate cases. It also supports real quantum hardware access and provides CPU/GPU/QPU hybrid deployment solutions since v0.9.Getting StartedPlease begin withQuick Startin thefull documentation.For more information on software usage, sota algorithm implementation and engineer paradigm demonstration, please refer to 70+example scriptsand 30+tutorial notebooks. API docstrings and test cases intestsare also informative.The following are some minimal demos.Circuit manipulation:importtensorcircuitastcc=tc.Circuit(2)c.H(0)c.CNOT(0,1)c.rx(1,theta=0.2)print(c.wavefunction())print(c.expectation_ps(z=[0,1]))print(c.sample(allow_state=True,batch=1024,format="count_dict_bin"))Runtime behavior customization:tc.set_backend("tensorflow")tc.set_dtype("complex128")tc.set_contractor("greedy")Automatic differentiations with jit:defforward(theta):c=tc.Circuit(2)c.R(0,theta=theta,alpha=0.5,phi=0.8)returntc.backend.real(c.expectation((tc.gates.z(),[0])))g=tc.backend.grad(forward)g=tc.backend.jit(g)theta=tc.array_to_tensor(1.0)print(g(theta))More highlight features for TensorCircuit (click for details)Sparse Hamiltonian generation and expectation evaluation:n=6pauli_structures=[]weights=[]foriinrange(n):pauli_structures.append(tc.quantum.xyz2ps({"z":[i,(i+1)%n]},n=n))weights.append(1.0)foriinrange(n):pauli_structures.append(tc.quantum.xyz2ps({"x":[i]},n=n))weights.append(-1.0)h=tc.quantum.PauliStringSum2COO(pauli_structures,weights)print(h)# BCOO(complex64[64, 64], nse=448)c=tc.Circuit(n)c.h(range(n))energy=tc.templates.measurements.operator_expectation(c,h)# -6Large-scale simulation with tensor network engine# tc.set_contractor("cotengra-30-10")n=500c=tc.Circuit(n)c.h(0)c.cx(range(n-1),range(1,n))c.expectation_ps(z=[0,n-1],reuse=False)Density matrix simulator and quantum info quantitiesc=tc.DMCircuit(2)c.h(0)c.cx(0,1)c.depolarizing(1,px=0.1,py=0.1,pz=0.1)dm=c.state()print(tc.quantum.entropy(dm))print(tc.quantum.entanglement_entropy(dm,[0]))print(tc.quantum.entanglement_negativity(dm,[0]))print(tc.quantum.log_negativity(dm,[0]))InstallThe package is written in pure Python and can be obtained via pip as:pipinstalltensorcircuitWe recommend you install this package with tensorflow also installed as:pipinstalltensorcircuit[tensorflow]Other optional dependencies include[torch],[jax],[qiskit]and[cloud].For the nightly build of tensorcircuit with new features, try:pipuninstalltensorcircuitpipinstalltensorcircuit-nightlyWe also haveDocker support.AdvantagesTensor network simulation engine basedJIT, AD, vectorized parallelism compatibleGPU support, quantum device access support, hybrid deployment supportEfficiencyTime: 10 to 10^6+ times acceleration compared to TensorFlow Quantum, Pennylane or QiskitSpace: 600+ qubits 1D VQE workflow (converged energy inaccuracy: < 1%)EleganceFlexibility: customized contraction, multiple ML backend/interface choices, multiple dtype precisions, multiple QPU providersAPI design: quantum for humans, less code, more powerBatteries includedTons of amazing features and built in tools for research (click for details)Supportsuper large circuit simulationusing tensor network engine.Supportnoisy simulationwith both Monte Carlo and density matrix (tensor network powered) modes.Supportapproximate simulationwith MPS-TEBD modes.Supportanalog/digital hybrid simulation(time dependent Hamiltonian evolution,pulselevel simulation) with neural ode modes.SupportFermion Gaussian statesimulation with expectation, entanglement, measurement, ground state, real and imaginary time evolution.Supportqudits simulation.Supportparallelquantum circuit evaluation acrossmultiple GPUs.Highly customizablenoise modelwith gate error and scalable readout error.Support fornon-unitarygate and post-selection simulation.Supportreal quantum devices accessfrom different providers.Scalable readout error mitigationnative to both bitstring and expectation level with automatic qubit mapping consideration.Advanced quantum error mitigation methodsand pipelines such as ZNE, DD, RC, etc.SupportMPS/MPOas representations for input states, quantum gates and observables to be measured.Supportvectorized parallelismon circuit inputs, circuit parameters, circuit structures, circuit measurements and these vectorization can be nested.Gradients can be obtained with bothautomatic differenationand parameter shift (vmap accelerated) modes.Machine learning interface/layer/modelabstraction in both TensorFlow and PyTorch for both numerical simulation and real QPU experiments.Circuit sampling supports both final state sampling and perfect sampling from tensor networks.Light cone reduction support for local expectation calculation.Highly customizable tensor network contraction path finder with opteinsum interface.Observables are supported in measurement, sparse matrix, dense matrix and MPO format.Super fast weighted sum Pauli string Hamiltonian matrix generation.Reusable common circuit/measurement/problem templates and patterns.Jittable classical shadow infrastructures.SOTA quantum algorithm and model implementations.Support hybrid workflows and pipelines with CPU/GPU/QPU hardware from local/cloud/hpc resources using tf/torch/jax/cupy/numpy frameworks all at the same time.ContributingStatusThis project is created and maintained byShi-Xin Zhangwith current core authorsShi-Xin ZhangandYu-Qin Chen. We also thankcontributionsfrom the open source community.CitationIf this project helps in your research, please cite our software whitepaper to acknowledge the work put into the development of TensorCircuit.TensorCircuit: a Quantum Software Framework for the NISQ Era(published in Quantum)which is also a good introduction to the software.Research works citing TensorCircuit can be highlighted inResearch and Applications section.GuidelinesFor contribution guidelines and notes, seeCONTRIBUTING.We welcomeissues,PRs, anddiscussionsfrom everyone, and these are all hosted on GitHub.LicenseTensorCircuit is open source, released under the Apache License, Version 2.0.ContributorsShixin Zhang💻📖💡🤔🚇🚧🔬👀🌍⚠️✅📢💬Yuqin Chen💻📖💡🤔🔬⚠️✅📢Jiezhong Qiu💻💡🤔🔬Weitang Li💻📖🤔🔬⚠️📢Jiace Sun💻📖💡🤔🔬⚠️Zhouquan Wan💻📖💡🤔🔬⚠️✅Shuo Liu💡🔬✅Hao Yu💻📖🚇⚠️✅Xinghan Yang📖🌍✅JachyMeow✅🌍Zhaofeng Ye🎨erertertet💻📖⚠️Yicong Zheng✅Zixuan Song📖🌍💻⚠️Hao Xie📖Pramit Singh⚠️Jonathan Allcock📖🤔📢nealchen2003📖隐公观鱼💻⚠️WiuYuan💡Felix Xu✅💻⚠️Hong-Ye Hu📖peilin✅💻⚠️📖Cristian Emiliano Godinez Ramirez💻⚠️ztzhu💻Rabqubit💡Kazuki Tsuoka💻Research and ApplicationsDQASFor the application of Differentiable Quantum Architecture Search, seeapplications.Reference paper:https://arxiv.org/abs/2010.08561(published in QST).VQNHEFor the application of Variational Quantum-Neural Hybrid Eigensolver, seeapplications.Reference paper:https://arxiv.org/abs/2106.05105(published in PRL) andhttps://arxiv.org/abs/2112.10380(published in AQT).VQEX-MBLFor the application of VQEX on MBL phase identification, see thetutorial.Reference paper:https://arxiv.org/abs/2111.13719(published in PRB).Stark-DTCFor the numerical demosntration of discrete time crystal enabled by Stark many-body localization, see the Floquet simulationdemo.Reference paper:https://arxiv.org/abs/2208.02866(published in PRL).RA-TrainingFor the numerical simulation of variational quantum algorithm training using random gate activation strategy by us, see theproject repo.Reference paper:https://arxiv.org/abs/2303.08154(published in PRR as a Letter).TenCirChemTenCirChemis an efficient and versatile quantum computation package for molecular properties. TenCirChem is based on TensorCircuit and is optimized for chemistry applications.Reference paper:https://arxiv.org/abs/2303.10825(published in JCTC).EMQAOA-DARBOFor the numerical simulation and hardware experiments with error mitigation on QAOA, see theproject repo.Reference paper:https://arxiv.org/abs/2303.14877.NN-VQAFor the setup and simulation code of neural network encoded variational quantum eigensolver, see thedemo.Reference paper:https://arxiv.org/abs/2308.01068.More worksMore research works and code projects using TensorCircuit (click for details)Neural Predictor based Quantum Architecture Search:https://arxiv.org/abs/2103.06524(published in Machine Learning: Science and Technology).Quantum imaginary-time control for accelerating the ground-state preparation:https://arxiv.org/abs/2112.11782(published in PRR).Efficient Quantum Simulation of Electron-Phonon Systems by Variational Basis State Encoder:https://arxiv.org/abs/2301.01442(published in PRR).Variational Quantum Simulations of Finite-Temperature Dynamical Properties via Thermofield Dynamics:https://arxiv.org/abs/2206.05571.Understanding quantum machine learning also requires rethinking generalization:https://arxiv.org/abs/2306.13461.Decentralized Quantum Federated Learning for Metaverse: Analysis, Design and Implementation:https://arxiv.org/abs/2306.11297. Code:https://github.com/s222416822/BQFL.Non-IID quantum federated learning with one-shot communication complexity:https://arxiv.org/abs/2209.00768(published in Quantum Machine Intelligence). Code:https://github.com/JasonZHM/quantum-fed-infer.Quantum generative adversarial imitation learning:https://doi.org/10.1088/1367-2630/acc605(published in New Journal of Physics).GSQAS: Graph Self-supervised Quantum Architecture Search:https://arxiv.org/abs/2303.12381.Practical advantage of quantum machine learning in ghost imaging:https://www.nature.com/articles/s42005-023-01290-1(published in Communications Physics).Zero and Finite Temperature Quantum Simulations Powered by Quantum Magic:https://arxiv.org/abs/2308.11616.Comparison of Quantum Simulators for Variational Quantum Search: A Benchmark Study:https://arxiv.org/abs/2309.05924.Statistical analysis of quantum state learning process in quantum neural networks:https://arxiv.org/abs/2309.14980(Pubilshed in NeurIPS).Generative quantum machine learning via denoising diffusion probabilistic models:https://arxiv.org/abs/2310.05866.Quantum imaginary time evolution and quantum annealing meet topological sector optimization:https://arxiv.org/abs/2310.04291.Google Summer of Code 2023 Projects (QML4HEP):https://github.com/ML4SCI/QMLHEP,https://github.com/Gopal-Dahale/qgnn-hep,https://github.com/salcc/QuantumTransformers.Absence of barren plateaus in finite local-depth circuits with long-range entanglement:https://arxiv.org/abs/2311.01393.Non-Markovianity benefits quantum dynamics simulation:https://arxiv.org/abs/2311.17622.If you want to highlight your research work or projects here, feel free to add by opening PR.