Package: projectq
ProjectQ is an open source effort for quantum computing.It features a compilation framework capable of
targeting various types of hardware, a high-performance quantum computer
simulator with emulation capabilities, and various compiler plug-ins.
This allows users torun quantum programs on the IBM Quantum Experience chip, AQT devices, AWS Braket, Azure Quantum, or IonQ service provided devicessimulate quantum programs on classical computersemulate quantum programs at a higher level of abstraction (e.g.,
mimicking the action of large oracles instead of compiling them to
low-level gates)export quantum programs as circuits (using TikZ)get resource estimatesExamplesFirst quantum programfromprojectqimportMainEngine# import the main compiler enginefromprojectq.opsimport(H,Measure,)# import the operations we want to perform (Hadamard and measurement)eng=MainEngine()# create a default compiler (the back-end is a simulator)qubit=eng.allocate_qubit()# allocate a quantum register with 1 qubitH|qubit# apply a Hadamard gateMeasure|qubit# measure the qubiteng.flush()# flush all gates (and execute measurements)print(f"Measured{int(qubit)}")# converting a qubit to int or bool gives access to the measurement resultProjectQ features a lean syntax which is close to the mathematical notation used in quantum physics. For example, a rotation of a qubit around the x-axis is usually specified as:The same statement in ProjectQ’s syntax is:Rx(theta)|qubitThe|-operator separates the specification of the gate operation (left-hand side) from the quantum bits to which the operation is applied (right-hand side).Changing the compiler and using a resource counter as a back-endInstead of simulating a quantum program, one can use our resource counter (as a back-end) to determine how many operations it would take on a future quantum computer with a given architecture. Suppose the qubits are arranged on a linear chain and the architecture supports any single-qubit gate as well as the two-qubit CNOT and Swap operations:fromprojectqimportMainEnginefromprojectq.backendsimportResourceCounterfromprojectq.opsimportQFTfromprojectq.setupsimportlinearcompiler_engines=linear.get_engine_list(num_qubits=16,one_qubit_gates='any',two_qubit_gates=(CNOT,Swap))resource_counter=ResourceCounter()eng=MainEngine(backend=resource_counter,engine_list=compiler_engines)qureg=eng.allocate_qureg(16)QFT|quregeng.flush()print(resource_counter)# This will output, among other information,# how many operations are needed to perform# this quantum fourier transform (QFT), i.e.,#   Gate class counts:#       AllocateQubitGate : 16#       CXGate : 240#       HGate : 16#       R : 120#       Rz : 240#       SwapGate : 262Running a quantum program on IBM’s QE chipsTo run a program on the IBM Quantum Experience chips, all one has to do is choose theIBMBackendand the corresponding setup:importprojectq.setups.ibmfromprojectq.backendsimportIBMBackendtoken='MY_TOKEN'device='ibmq_16_melbourne'compiler_engines=projectq.setups.ibm.get_engine_list(token=token,device=device)eng=MainEngine(IBMBackend(token=token,use_hardware=True,num_runs=1024,verbose=False,device=device),engine_list=compiler_engines,)Running a quantum program on AQT devicesTo run a program on the AQT trapped ion quantum computer, choose theAQTBackendand the corresponding setup:importprojectq.setups.aqtfromprojectq.backendsimportAQTBackendtoken='MY_TOKEN'device='aqt_device'compiler_engines=projectq.setups.aqt.get_engine_list(token=token,device=device)eng=MainEngine(AQTBackend(token=token,use_hardware=True,num_runs=1024,verbose=False,device=device),engine_list=compiler_engines,)Running a quantum program on a AWS Braket provided deviceTo run a program on some of the devices provided by the AWS Braket service,
choose theAWSBraketBackend. The currend devices supported are Aspen-8 from Rigetti,
IonQ from IonQ and the state vector simulator SV1:fromprojectq.backendsimportAWSBraketBackendcreds={'AWS_ACCESS_KEY_ID':'your_aws_access_key_id','AWS_SECRET_KEY':'your_aws_secret_key',}s3_folder=['S3Bucket','S3Directory']device='IonQ'eng=MainEngine(AWSBraketBackend(use_hardware=True,credentials=creds,s3_folder=s3_folder,num_runs=1024,verbose=False,device=device,),engine_list=[],)NoteIn order to use the AWSBraketBackend, you need to install ProjectQ with the ‘braket’ extra requirement:python3-mpipinstallprojectq[braket]orcd/path/to/projectq/source/codepython3-mpipinstall-ve.[braket]Running a quantum program on a Azure Quantum provided deviceTo run a program on devices provided by theAzure Quantum.UseAzureQuantumBackendto run ProjectQ circuits on hardware devices and simulator devices from providersIonQandQuantinuum.fromprojectq.backendsimportAzureQuantumBackendazure_quantum_backend=AzureQuantumBackend(use_hardware=False,target_name='ionq.simulator',resource_id='<resource-id>',location='<location>',verbose=True)NoteIn order to use the AzureQuantumBackend, you need to install ProjectQ with the ‘azure-quantum’ extra requirement:python3-mpipinstallprojectq[azure-quantum]orcd/path/to/projectq/source/codepython3-mpipinstall-ve.[azure-quantum]Running a quantum program on IonQ devicesTo run a program on the IonQ trapped ion hardware, use theIonQBackendand its corresponding setup.Currently available devices are:ionq_simulator: A 29-qubit simulator.ionq_qpu: A 11-qubit trapped ion system.importprojectq.setups.ionqfromprojectqimportMainEnginefromprojectq.backendsimportIonQBackendtoken='MY_TOKEN'device='ionq_qpu'backend=IonQBackend(token=token,use_hardware=True,num_runs=1024,verbose=False,device=device,)compiler_engines=projectq.setups.ionq.get_engine_list(token=token,device=device,)eng=MainEngine(backend,engine_list=compiler_engines)Classically simulate a quantum programProjectQ has a high-performance simulator which allows simulating up to about 30 qubits on a regular laptop. See thesimulator tutorialfor more information. Using the emulation features of our simulator (fast classical shortcuts), one can easily emulate Shor’s algorithm for problem sizes for which a quantum computer would require above 50 qubits, see ourexample codes.The advanced features of the simulator are also particularly useful to investigate algorithms for the simulation of quantum systems. For example, the simulator can evolve a quantum system in time (without Trotter errors) and it gives direct access to expectation values of Hamiltonians leading to extremely fast simulations of VQE type algorithms:fromprojectqimportMainEnginefromprojectq.opsimportAll,Measure,QubitOperator,TimeEvolutioneng=MainEngine()wavefunction=eng.allocate_qureg(2)# Specify a Hamiltonian in terms of Pauli operators:hamiltonian=QubitOperator("X0 X1")+0.5*QubitOperator("Y0 Y1")# Apply exp(-i * Hamiltonian * time) (without Trotter error)TimeEvolution(time=1,hamiltonian=hamiltonian)|wavefunction# Measure the expection value using the simulator shortcut:eng.flush()value=eng.backend.get_expectation_value(hamiltonian,wavefunction)# Last operation in any program should be measuring all qubitsAll(Measure)|quregeng.flush()Getting startedTo start using ProjectQ, simply follow the installation instructions in thetutorials. There, you will also find OS-specific hints, a small introduction to the ProjectQ syntax, and a fewcode examples. More example codes and tutorials can be found in the examples folderhereon GitHub.Also, make sure to check out theProjectQ
websiteand the detailedcode documentation.How to contributeFor information on how to contribute, please visit theProjectQ
websiteor send an e-mail toinfo@projectq.ch.Please citeWhen using ProjectQ for research projects, please citeDamian S. Steiger, Thomas Haener, and Matthias Troyer “ProjectQ: An
Open Source Software Framework for Quantum Computing”Quantum 2, 49 (2018)(published onarXivon 23 Dec 2016)Thomas Haener, Damian S. Steiger, Krysta M. Svore, and Matthias Troyer
“A Software Methodology for Compiling Quantum Programs”Quantum Sci. Technol. 3 (2018) 020501(published onarXivon 5 Apr 2016)AuthorsThe first release of ProjectQ (v0.1) was developed byThomas
HaenerandDamian S.
Steigerin the group ofProf. Dr. Matthias
Troyerat ETH
Zurich.ProjectQ is constantly growing andmany other peoplehave already contributed to it in the meantime.LicenseProjectQ is released under the Apache 2 license.