Package: tequila-basic
TequilaTequila is an abstraction framework for (variational) quantum algorithms.It operates on abstract data structures allowing the formulation, combination, automatic differentiation and optimization of generalized objectives.
Tequila can execute the underlying quantum expectation values on state of the art simulators as well as on real quantum devices.overview articletequila in a nutshellgetting startedcircuits in tequilanotebook collectiontalks and slidesInstallationRecommended Python version is 3.8-3.9.Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.Install from PyPiDo notinstall like this: (Minecraft lovers excluded)pip install tequilaYou can install tequila from PyPi as:pipinstalltequila-basicthis will install tequila with all essential dependencies.
We recommend to install some fast quantum backends, like qulacs or qibo, as well.
Those can be installed before or after you install tequila.# install basic tequilapipinstalltequila-basic# install qulacs and/or other backends and use it within tequilapipinstallqulacsInstall from githubYou can installtequiladirectly with pip over:pipinstallgit+https://github.com/tequilahub/tequila.gitInstall from devel branch (most recent updates):pipinstallgit+https://github.com/tequilahub/tequila.git@develTequila Hello World# optimize a one qubit example# define a variablea=tq.Variable("a")# define a simple circuitU=tq.gates.Ry(angle=a*pi,target=0)# define an HamiltonianH=tq.paulis.X(0)# define an expectation valueE=tq.ExpectationValue(H=H,U=U)# optimize the expectation valueresult=tq.minimize(method="bfgs",objective=E**2)# check out the optimized wavefunctionwfn=tq.simulate(U,variables=result.angles)print("optimized wavefunction = ",wfn)# plot information about the optimizationresult.history.plot("energies")result.history.plot("angles")result.history.plot("gradients")Chemistry Hello World (Madness backend)see below for installation of dependenciesimporttequilaastq# initialize molecule (also works over .xyz files --> see next example)geomstring="Li 0.0 0.0 0.0\nH 0.0 0.0 1.6"mol=tq.Molecule(geometry=geomstring)# get the qubit hamiltonianH=mol.make_hamiltonian()# get the ansatz (circuit)U=mol.make_ansatz(name="SPA")# or e.g. UpCCGSD# define the expectation valueE=tq.ExpectationValue(H=H,U=U)# minimize the expectation valueresult=tq.minimize(E)# optional:compute classical reference energies# needs pyscf as wellcisd=mol.compute_energy("cisd")fci=mol.compute_energy("fci")print("VQE :{:+2.8}f".format(result.energy))print("CISD:{:+2.8}f".format(cisd))print("FCI :{:+2.8}f".format(fci))Chemistry Hello World (Psi4 or PySCF backend)see below for installation of dependencies# define a molecule within an active spaceactive_orbitals=[1,2,5]molecule=tq.quantumchemistry.Molecule(geometry="lih.xyz",basis_set='6-31g',active_orbitals=active,transformation="bravyi-kitaev")# get the qubit hamiltonianH=molecule.make_hamiltonian()# create an k-UpCCGSD circuit of order kU=molecule.make_ansatz(name="UpCCGSD")# define the expectationvalueE=tq.ExpectationValue(H=H,U=U)# compute reference energiesfci=molecule.compute_energy("fci")cisd=molecule.compute_energy("detci",options={"detci__ex_level":2})# optimizeresult=tq.minimize(objective=E,method="BFGS",initial_values=0.0)print("VQE :{:+2.8}f".format(result.energy))print("FCI :{:+2.8}f".format(fci))Do you want to create your own methods? Check out thetutorials!Some Research projects using TequilaJ.S. Kottmann, A. Anand, A. Aspuru-Guzik.A Feasible Approach for Automatically Differentiable Unitary Coupled-Cluster on Quantum Computers.Chemical Science, 2021,doi.org/10.1039/D0SC06627C.arxiv:2011.05938General techniques are implemented in the chemistry modules of tequila.See thetutorialsfor examples.J.S. Kottmann, P. Schleich, T. Tamayo-Mendoza, A. Aspuru-Guzik.Reducing Qubit Requirements while Maintaining Numerical Precision for the Variational Quantum Eigensolver: A Basis-Set-Free Approach.J.Phys.Chem.Lett., 2021,doi.org/10.1021/acs.jpclett.0c03410.arxiv:2008.02819example codetutorial on the madness interfaceA. Cervera-Lierta, J.S. Kottmann, A. Aspuru-Guzik.The Meta-Variational Quantum Eigensolver.arxiv:2009.13545example codeJ.S. Kottmann, M. Krenn, T.H. Kyaw, S. Alperin-Lea, A. Aspuru-Guzik.Quantum Computer-Aided design of Quantum Optics Hardware.arxiv:2006.03075example codeslidesA. Anand, M. Degroote, A. Aspuru-Guzik.Natural Evolutionary Strategies for Variational Quantum Computation.arxiv:2012.00101J. S. Kottmann, A. Aspuru-Guzik,Optimized Low-Depth Quantum Circuits for Molecular Electronic Structure using a Separable Pair Approximation,arxiv:2105.03836example codeK. Choudhary,Quantum Computation for Predicting Electron and Phonon Properties of Solidsarxiv:2102.11452P. Schleich, J.S. Kottmann, A. Aspuru-Guzik,Improving the Accuracy of the Variational Quantum Eigensolver for Molecular Systems by the Explicitly-Correlated Perturbative [2]-R12-Correctionarxiv:2110.06812tutorialM. Weber, A. Anand, A. Cervera-Lierta, J. S. Kottmann, T.-H. Kyaw, B. Li, A. Aspuru-Guzik, C. Zhang and Z. Zhao,Toward Reliability in the NISQ Era: Robust Interval Guarantee for Quantum Measurements on Approximate Statesarxiv:2110.09793tutorialM. S. Rudolph, S. Sim, A. Raza, M. Stechly, J. R. McClean, E. R. Anschuetz, L. Serrano, A. Perdomo-OrtizORQVIZ: Visualizing High-Dimensional Landscapes in Variational Quantum Algorithmsarxiv:2111.04695P. SchleichRegularization of Quantum Chemistryon Quantum Computers by means of Explicit CorrelationMaster thesisT.-H. Kyaw, T. Menke, S. Sim, A. Anand, N. P. D. Sawaya, W. D. Oliver, G. G. Guerreschi, A. Aspuru-GuzikQuantum computer-aided design: digital quantum simulation of quantum processorsarxiv:2006.03070Z. P. Bansingh, T.-C. Yen, P. D. Johnson, A. F. IzmaylovFidelity overhead for non-local measurements in variational quantum algorithmsarxiv:2205.07113H. Lim, H.-N. Jeon, J.-K. Rhee, B. Oh, K. T. NoQuantum computational study of chloride ion attack on chloromethane for chemical accuracy and quantum noise effects with UCCSD and k-UpCCGSD ansatzesarxiv:2112.15314A, Meijer- van de Griend, J. K. NurminenQuantMark: A Benchmarking API for VQE AlgorithmsDOI:10.1109/TQE.2022.3159327QuantMark CodebaseA. Anand, J.S. Kottmann, A. Aspuru-GuzikQuantum compression with classically simulatable circuitscodearxiv:2207.02961J.S. KottmannMolecular Circuit Design: A Graph-Based Approacharxiv:2207.12421example codeT.-H. Kyaw, M. B. Soley, B. Allen, P. Bergold, C. Sun, V. S. Batista, A. Aspuru-GuzikVariational quantum iterative power algorithms for global optimizationarxiv:2208.10470codeR.A. Lang, A. Ganeshram, A. IzmaylovGrowth reduction of similarity transformed electronic Hamiltonians in qubit spacearxiv:2210.03875K. Gratsea, C. Sun, P.D. JohnsonWhen to Reject a Ground State Preparation Algorithmarxiv:2212.09492R.P. Pothukuchi, L. Lufkin, Y.J. Shen, A. Simon, R. Thorstenson, B.E. Trevisan, M. Tu, M. Yang, B. Foxman, V. S. Pothukuchi, G. Epping, B. J. Jongkees, T.-H. Kyaw, J. R. Busemeyer, J. D Cohen, A. BhattacharjeeQuantum Cognitive Modeling: New Applications and Systems Research Directionsarxiv:2309.00597T.-H. Kyaw, M. B. Soley, B. Allen, P. Bergold, C. Sun, V.S. Batista and A. Aspuru-GuzikBoosting quantum amplitude exponentially in variational quantum algorithms10.1088/2058-9565/acf4baA.G. Cadavid, I. Montalban, A. Dalal, E. Solano, N.N. HegadeEfficient DCQO Algorithm within the Impulse Regime for Portfolio Optimizationarxiv:2308.15475Let us know, if you want your research project and/or tutorial to be included in this list!DependenciesSupport for additional optimizers or quantum backends can be activated by intalling them in your environment.
Tequila will then detect them automatically.
Currently those are:PhoenicsandGPyOpt.
Quantum backends are treated in the same way.Quantum BackendsCurrently supportedQulacs(recommended)Qibo-- currently needs to be qibo==0.1.1QiskitCirqPyQuilQLM(works also whithmyQLM)Tequila detects backends automatically if they are installed on your systems.
All of them are available over standard pip installation like for examplepip install qulacs.
For best performance it is recommended to havequlacsinstalled.QuantumChemistry:Currently supportedPsi4.In a conda environment this can be installed withcondainstallpsi4-cpsi4Here is a smalltutorialthat illustrates the usage.MadnessIn a conda environment this can be installed withcondainstallmadtequila-ckottmannThis installs a modified version of madness ready to use with tequila.Alternatively it can be compiled from the sources provided in thisfork(follow readme instructions there).Here is a smalltutorialthat illustrates the usage. For fast performance it is recommended to not use the conda package.PySCFInstall withpipinstallpyscfWorks similar as Psi4. Classical methods are also integrated in the madness interface allowing to use them in a basis-set-free representation.DocumentationYou can build the documentation by navigating todocsand enteringmake html.
Open the documentation with a browser over likefirefox docs/build/html/index.htmlNote that you will need some additional python packages likesphinxandmr2that are not explicitly listed in the requirements.txtYou can also visit our prebuild onlinedocumentationthat will correspond to the github master branchHow to contributeIf you find any bugs or inconveniences intequilaplease don't be shy and let us know.
You can do so either by raising an issue here on github or contact us directly.If you already found a solution you can contribute totequilaover a pull-request.
Here is how that works:Make a fork oftequilato your own github account.Checkout thedevelbranch and make sure it is up to date with the maingithub repository.Create and checkout a new branch fromdevelviagit branch pr-my-branch-namefollowed bygit checkout pr-my-branch-name. By typinggit branchafterwards you can check which branch is currently checked out on your computer.Introduce changes to the code and commit them with git.Push the changes toyourgithub accountLog into github and create a pull request to the maingithub repository. The pull-request should be directed to thedevelbranch (but we can also change that afterwards).If you plan to introduce major changes to the base library it can be beneficial to contact us first.
This way we might be able to avoid conflicts before they arise.If you usedtequilafor your research, feel free to include your algorithms here, either by integrating it into the core libraries or by demonstrating it with a notebook in the tutorials section. If you let us know about it, we will also add your research article in the list of research projects that use tequila (see above).TroubleshootingIf you experience trouble of any kind or if you either want to implement a new feature or want us to implement a new feature that you need:
Don't hesitate to contact us directly or raise an issue here on github.PySCFIf pyscf crashes on import withUsing default_file_mode other than 'r' is no longer supported. Pass the mode to h5py.File() insteadthen you need to downgrade the h5py versionpip install --upgrade 'h5py <= 3.1'The issue will probably be fixed soon in pyscf.import errors on openfermion and cirqThis is fixed on master and devel but not yet on PyPi (v1.5.1)You can avoid it by downgrading cirq and openfermionpipinstall--upgrade"openfermion<=1.0.0"pipinstall--upgrade"cirq<=0.9.1"Qiskit backendQiskit version 0.25 is not yet supported.pip install --upgrade qiskit<0.25fixes potential issues. If not: Please let us know.Circuit drawingStandard graphical circuit representation within a Jupyter environment is often done usingtq.draw.
Without further keywordstequialwill try to create and compile aqpicfile.
For proper display you will need the following dependencies: qpic, pdflatex and convert/ImageMagick (pre-installed on most GNU/Linux distributions, not pre-installed on macs).
On GNU/Linux distributions sometimes the permissions ofconvertto convert pdf to png are not granted, resulting in an error when trying to usetq.draw.
Clickherefor a possible solution.In general, there is no reason to worry iftq.drawdoes not function properly.
It is just one way to display circuits, but not neccessary to have.
Alternatives are:Usetq.draw(circuit, backend="qiskit")(orbackend=cirq)translate to qiskit/cirq and use their functionality (qiskit_circuit = tq.compile(circuit, backend='qiskit').circuit)directly create pdfs:tq.circuit.export_to(circuit, filename="my_name.pdf")(will also createmy_name.qpicthat can be used with qpic)useprint(circuit)(does not look pretty, but carries the same information).become a contributor and implement your own graphical circuit representation and create a pull-request.Qulacs simulatorYou will need cmake to install the qulacs simulatorpip install cmakeYou don't needqulacsfor tequila to run (although is is recommended)
To install withoutqulacsjust remove thequlacsline fromrequirements.txtIt can be replaced by one (or many) of the other supported simulators.
Note that simulators can also be installed on a later point, they don't need to be installed withtequila.
As long as they are installed within the same python environmenttequilacan detect them.WindowsYou can in principle use tequila with windows as OS and have almost full functionality.
You will need to replaceJaxwithautogradfor it to work.
In order to do so: Removejaxandjaxlibfromsetup.pyandrequirements.txtand addautogradinstead.In order to install qulacs you will need latest GNU compilers (at least gcc-7).
They can be installed for example over visual studio.Mac OSTequila runs on Mac OSX.
You might get in trouble with installing qulacs since it currently does not work with Apple's clang compiler.
You need to install latest GNU compile (at least gcc-7 and g++7) and set them as default before installing qulacs over pip.Qibo and GPyOptCurrently you can't use Qibo and GPyOpt within the same environment.