Package: mindquantum
MindQuantum查看中文MindQuantumWhat is MindQuantumFirst experienceBuild parameterized quantum circuitTrain quantum neural networkTutorialsAPIInstallationConfirming System Environment InformationInstall by Source CodeInstall by pipInstall MindSporeInstall MindQuantumVerifying Successful InstallationInstall with DockerNoteQuick StartDocsCommunityGovernanceContributingHow to citeLicenseWhat is MindQuantumMindQuantum is a new-generation quantum computing framework based on MindSpore, focusing on the implementation of NISQ algorithms. It combines the HiQ high-performance quantum computing simulator with the parallel automatic differentiation capability of MindSpore. MindQuantum is easy-to-use with ultra-high performance. It can efficiently handle problems like quantum machine learning, quantum chemistry simulation, and quantum optimization. MindQuantum provides an efficient platform for researchers, teachers and students to quickly design and verify quantum algorithms, making quantum computing at your fingertips.First experienceBuild parameterized quantum circuitThe below example shows how to build a parameterized quantum circuit.frommindquantumimport*importnumpyasnpencoder=Circuit().h(0).rx({'a0':2},0).ry('a1',1)print(encoder)print(encoder.get_qs(pr={'a0':np.pi/2,'a1':np.pi/2},ket=True))Then you will get,┏━━━┓┏━━━━━━━━━━┓
q0:──┨H┠─┨RX(2*a0)┠───┗━━━┛┗━━━━━━━━━━┛┏━━━━━━━━┓
q1:──┨RY(a1)┠───────────┗━━━━━━━━┛

-1/2j¦00⟩
-1/2j¦01⟩
-1/2j¦10⟩
-1/2j¦11⟩In jupyter notebook, we can just callsvg()of any circuit to display the circuit in svg picture (darkandlightmode are also supported).circuit=(qft(range(3))+BarrierGate(True)).measure_all()circuit.svg()# circuit.svg('light')Train quantum neural networkansatz=CPN(encoder.hermitian(),{'a0':'b0','a1':'b1'})sim=Simulator('mqvector',2)ham=Hamiltonian(-QubitOperator('Z0 Z1'))grad_ops=sim.get_expectation_with_grad(ham,encoder.as_encoder()+ansatz.as_ansatz(),)importmindsporeasmsms.set_context(mode=ms.PYNATIVE_MODE,device_target='CPU')net=MQLayer(grad_ops)encoder_data=ms.Tensor(np.array([[np.pi/2,np.pi/2]]))opti=ms.nn.Adam(net.trainable_params(),learning_rate=0.1)train_net=ms.nn.TrainOneStepCell(net,opti)foriinrange(100):train_net(encoder_data)print(dict(zip(ansatz.params_name,net.trainable_params()[0].asnumpy())))The trained parameters are,{'b1':1.5720831,'b0':0.006396801}TutorialsBasic usageVariational Quantum CircuitQuantum simulatorInitial experience of quantum neural networkAdvanced gradient calculation of variational quantum circuitsAdvanced operations of quantum circuitQuantum MeasurementNoisy Quantum CircuitNoise simulatorQubit MappingBloch SphereVariational quantum algorithmClassification of iris by quantum neural networkQuantum Approximate Optimization AlgorithmThe Application of Quantum Neural Network in NLPVQE Application in Quantum Chemistry ComputingEquivalence Checking of Parameterized Quantum CircuitsGENERAL QUANTUM ALGORITHMQuantum Phase Estimation algorithmGrover search and long algorithms based on MindQuantumShor’s algorithm based on MindQuantumAPIFor more API, please refer toMindQuantum API.InstallationConfirming System Environment InformationThe hardware platform should be CPU with avx2 supported.Refer toMindQuantum Installation Guide, install MindSpore, version 1.4.0 or later is required.Seesetup.pyfor the remaining dependencies.Install by Source Code1.Download Source Code from Giteecd~
gitclonehttps://gitee.com/mindspore/mindquantum.git2.Compiling MindQuantumcd~/mindquantum
bashbuild.shcdoutput
pipinstallmindquantum-*.whlInstall by pipInstall MindSporePlease refer toMindSpore installation guideto install MindSpore that at least 1.4.0 version.Install MindQuantumpipinstallmindquantumBuild from sourceClone source.cd~
gitclonehttps://gitee.com/mindspore/mindquantum.gitBuild MindQuantumForlinux system, please make sure your cmake version >= 3.18.3, and then run code:cd~/mindquantum
bashbuild.sh--giteeHere--giteeis telling the script to download third party from gitee. If you want to download from github, you can ignore this flag. If you want to build under GPU, please make sure you have install CUDA 11.x and the GPU driver, and then run code:cd~/mindquantum
bashbuild.sh--gitee--gpuForwindows system, please make sure you have install MinGW-W64 and CMake >= 3.18.3, and then run:cd~/mindquantum
./build.bat/GiteeForMac system, please make sure you have install openmp and CMake >= 3.18.3, and then run:cd~/mindquantum
bashbuild.sh--giteeInstall whlPlease go to output, and install mindquantum wheel package bypip.Verifying Successful InstallationSuccessfully installed, if there is no error message such as No module named 'mindquantum' when execute the following command:python-c'import mindquantum'Install with DockerMac or Windows users can install MindQuantum through Docker. Please refer toDocker installation guideNotePlease set the parallel core number before running MindQuantum scripts. For example, if you want to set the parallel core number to 4, please run the command below:exportOMP_NUM_THREADS=4For large servers, please set the number of parallel kernels appropriately according to the size of the model to achieve optimal results.Building binary wheelsIf you would like to build some binary wheels for redistribution, please have a look to ourbinary wheel building guideQuick StartFor more details about how to build a parameterized quantum circuit and a quantum neural network and how to train these models, see theMindQuantum Tutorial.DocsMore details about installation guide, tutorials and APIs, please see theUser Documentation.CommunityGovernanceCheck out how MindSpore Open Governanceworks.ContributingWelcome contributions. See ourContributor Wikifor more details.How to citeWhen using MindQuantum for research, please cite:@misc{mq_2021,author={MindQuantumDeveloper},title={MindQuantum,version0.6.0},month={March},year={2021},url={https://gitee.com/mindspore/mindquantum}}LicenseApache License 2.0