Package: orqviz
orqvizA Python package for easilyvisualizing the loss landscapeof Variational Quantum Algorithms byZapata Computing Inc.orqvizprovides a collection of tools which quantum researchers and enthusiasts alike can use for their simulations. It works with any framework for running quantum circuits, for exampleqiskit,cirq,pennylane, andOrquestra. The package contains functions to generate data, as well as a range of flexible plotting and helper functions.orqvizis light-weight and has very few dependencies.Getting startedIndoc/examples/we provide a range ofJupyter notebookexamples fororqviz. We have four Jupyter notebooks with tutorials for how to get started with any quantum circuit simulation framework you might use. You will find examples withqiskit,cirq,pennylaneand Zapata'sOrquestralibrary. The tutorials are not exhaustive, but they do provide a full story that you can follow along.Inthis notebookwe have theSombreroexample that we showcase in our paper. We also have anadvanced example notebookwhich provides a thorough demonstration of the flexibility of theorqvizpackage.We recently published a paper on arXiv where we review the tools available withorqviz:ORQVIZ: Visualizing High-Dimensional Landscapes in Variational Quantum AlgorithmsFind a brief overview of the visualization techniques onYouTube!InstallationYou can install our package using the following command:pipinstallorqvizAlternatively you can build the package from source. This is especially helpful if you would like to contribute toorqvizgitclonehttps://github.com/zapatacomputing/orqviz.gitcdorqviz
pipinstall-e./Examplesimportorqvizimportnumpyasnpnp.random.seed(42)defloss_function(pars):returnnp.sum(np.cos(pars))**2+np.sum(np.sin(30*pars))**2n_params=42params=np.random.uniform(-np.pi,np.pi,size=n_params)dir1=orqviz.geometric.get_random_normal_vector(n_params)dir2=orqviz.geometric.get_random_orthonormal_vector(dir1)scan2D_result=orqviz.scans.perform_2D_scan(params,loss_function,direction_x=dir1,direction_y=dir2,n_steps_x=100)orqviz.scans.plot_2D_scan_result(scan2D_result)This code results in the following plot:FAQWhat are the expected type and shape for the parameters?Parameters should be of typenumpy.ndarrayfilled with real numbers. In recent releases, the shape of the parameters can be arbitrary, as long asnumpyallows it, i.e., you cannot have inconsistent sizes per dimension. Until version0.1.1, the parameter array needed to be one-dimensional.What is the format of theloss_functionthat mostorqvizmethods expect?We define aloss_functionas a function which receives only the parameters of the model and returns a floating point/ real number. That value could for example be the cost function of an optimization problem, the prediction of a classifier, or the fidelity with respect to a fixed quantum state. All the calculation that needs to be performed to get to these values needs to happen in your function. Check out the above code as a minimal example.What can I do if my loss function requires additional arguments?In that case you need to wrap the function into another function such that it again receives only the parameters of the model. We built a wrapper class calledLossFunctionWrapperthat you can import fromorqviz.loss_function. It is a thin wrapper with helpful perks such as measuring the average evaluation time of a single loss function call, and the total number of calls.AuthorsThe leading developer of this package is Manuel Rudolph at Zapata Computing.For questions related to the visualization techniques, contact Manuel viamanuel.rudolph@zapatacomputing.com.The leading software developer of this package is Michał Stęchły at Zapata Computing.For questions related to technicalities of the package, contact Michał viamichal.stechly@zapatacomputing.com.Thank you to Sukin Sim and Luis Serrano from Zapata Computing for their contributions to the tutorials.You can also contact us or ask general questions usingGitHub Discussions.For more specific code issues, bug fixes, etc. please open aGitHub issuein theorqvizrepository.If you are doing research usingorqviz, please citeourorqvizpaper:Manuel S. Rudolph, Sukin Sim, Asad Raza, Michał Stęchły, Jarrod R. McClean, Eric R. Anschuetz, Luis Serrano, and Alejandro Perdomo-Ortiz. ORQVIZ: Visualizing High-Dimensional Landscapes in Variational Quantum Algorithms. 2021. arXiv:2111.04695How to contributePlease see ourContribution Guidelines.