libquil provides a C API for Quilc and QVM.
We provide pre-built binaries for the following systems
- Linux x64 (tested specifically on Ubuntu)
- macOS x64
Note that ARM is not yet supported on any of the above.
These libraries are required by libquil:
BLAS,LAPACKfor linear algebra routineslibffifor cross-language executionlibzfor compression
On systems which use apt to install packages (e.g. Ubuntu), these libraries can be installed with the command
sudo apt install libblas-dev libffi-dev libffi7 liblapack-dev libz-dev
On systems which use brew to install packages (e.g macOS), these libraries can be installed with the command
brew install lapack openblas libffi
A script is provided to automate installation of the library. It will detect the host operating system and install the library to an appropriate location. A version identifier can be provided to install a particular version of the library. If no version is provided, the latest version of the library will be installed.
Note: the installer script requires
sudoto install the library into the system.
Note: on macOS,
sudois also used to mark the library files as trusted. The files themselves are not signed and macOS will, by default, flag them as insecure.
Run the following command
curl https://raw.githubusercontent.com/rigetti/libquil/main/install.sh | bash
If you would like to install a particular version of the library, run the following command
curl https://raw.githubusercontent.com/rigetti/libquil/main/install.sh | bash -s <version-identifier>
replacing <version-identifier> with the desired version, e.g. 0.3.0.
If you would like to manually install the library (for example in the case where you want to install the library to a non-standard location), find the appropriate version and operating system from the releases page. Within the .zip archive you will find the library and header files that are required to use the library. Move these into your file system.
-
libquil_error_tEnum which indicates whether a function call was successful (LIBQUIL_ERROR_SUCCESS) or not (LIBQUIL_ERROR_FAIL). Most functions will have this as their return type. -
libquil_error_t libquil_error(char** error_msg)Used to retrieve the last error message from libquil.When any error is encountered by libquil, it will be stored in memory. A subsequent call to
libquil_errorwill return that error message. After callinglibquil_error, the error is cleared from memory such that immediately callinglibquil_errorafter a previous call will return an empty string (indicating no errors since the previous error).
program_memory_type_tThe Quil program memory types.LIBQUIL_TYPE_BITis the QuilBITmemory typeLIBQUIL_TYPE_OCTETis the QuilOCTETmemory typeLIBQUIL_TYPE_INTEGERis the QuilINTEGERmemory typeLIBQUIL_TYPE_REALis the QuilREALmemory type
-
quil_programAn opaque pointer to a Quilc program object -
chip_specificationAn opaque pointer to a Quilc chip specification object -
quilc_version_infoAn opaque pointer to a Quilc version object -
quilc_compilation_metadataStores compilation metadata returned byquilc_compile_protoquil
-
libquil_error quilc_get_version_info(quilc_version_info *version_info)Allocates aquilc_version_infoobject and stores the pointer to it inversion_info -
libquil_error quilc_version_info_version(quilc_version_info version_info, char** version)Allocates memory which indicates the version string of Quilc and stores the pointer to it inversion -
libquil_error quilc_version_info_githash(quilc_version_info version_info, char** githash)Allocates memory which indicates the githash string of Quilc and stores the pointer to it inversion -
libquil_error_t quilc_parse_quil(char* program, quil_program *result)Parses theprogramstring and stores it in aquil_program -
libquil_error_t quilc_print_program(quil_program program)Prints theprogramto stdout -
libquil_error_t quilc_program_string(quil_program program, char** result)Allocates and populates achar*which is the givenprogram's string representation -
libquil_error_t quilc_compile_quil(quil_program program, chip_specification chip_spec, quil_program* compiled_program)Compiles theprogramfor the provided chip specification and stores it in aquil_program -
libquil_error_t quilc_compile_protoquil(quil_program program, chip_specification chip_spec, quil_program* compiled_program)Compiles the (protoquil)programfor the provided chip specification and stores it in aquil_program -
libquil_error_t quilc_conjugate_pauli_by_clifford(void* pauli_indices, int pauli_indices_len, void* pauli_terms, int pauli_terms_len, quil_program clifford, void* phase, void* pauli)Conjugates a Pauli operator by a Clifford operatorAfter having called
quilc_conjugate_pauli_by_clifford:phasewill be the encoded global phase factorpauliwill be a string description of the resulting encoded Pauli operator
-
libquil_error_t quilc_generate_rb_sequence(int depth, int qubits, void* gateset_ptr, int gateset_len, int seed, void* interleaver, void* results_ptr, void* result_lens_ptr)Generates a randomized benchmarking sequenceAfter having called
quilc_generate_rb_sequence:result_lens_ptr(a pre-allocatedintarray of lengthdepth) will contain integers describing the segmentation ofresults_ptrresults_ptrwill be populated with a flat array of integer values, the interpretation of which depends onresults_len_ptr. This memory should be freed withfree.
-
libquil_error_t quilc_build_nq_linear_chip(int n, chip_specification* chip_spec)Builds a linearly-connectedn-qubit chip specification and stores it inchip_spec -
libquil_error_t quilc_chip_spec_from_isa_descriptor(char* isa_json, chip_specification* chip_spec)Builds an arbitrary chip specification using the JSON-encoded ISA description -
libquil_error_t quilc_program_memory_type(quil_program program, char* region_name, program_memory_type* region_type)Returns thequilc_program_memory_typefor the given memory region
qvm_multishot_addressesAn opaque pointer to a QVM multishot addresses objectlibquil_error_t qvm_multishot_resultAn opaque pointer to a QVM multishot result objectlibquil_error_t qvm_version_infoAn opaque pointer to a QVM version info object
-
libquil_error_t qvm_get_version_info(qvm_version_info* version_info)Get a newqvm_version_info -
libquil_error_t qvm_version_info_version(qvm_version_info version_info, char** version)Populate a string at*versionwhich has the QVM version -
libquil_error_t qvm_version_info_githash(qvm_version_info version_info, char** version)Populate a string at*githashwhich has the QVM githash -
libquil_error_t qvm_multishot_addresses_new(qvm_multishot_addresses* addresses)Allocate memory for theqvm_multishot_addressesobject -
libquil_error_t qvm_multishot_addresses_set(qvm_multishot_addresses addresses, char* name, void* indices, int len)Set the indices of a memory region which should be collected when usingqvm_multishot.For example, if your register was named
roand you wanted to get indices 0 and 2, you would provide"ro"fornameand{0, 2}forindices. (lenis the length ofindices.) -
`libquil_error_t qvm_multishot_addresses_get_all(qvm_multishot_addresses addresses, char* name, int shot_index, void** results, int* results_len) Request all results for the given memory address.
On return,
*resultswill be an array of lengthresults_len. The specific data type contained in the array is to be interpreted by the caller. -
libquil_error_t qvm_multishot(quil_program program, qvm_multishot_addresses addresses, int trials, double* gate_noise, double* measurement_noise, qvm_multishot_result *result)Executeprogramon the QVMtrials-number of times, collecting theaddressesintoresult.gate_noiseandmeasurement_noiseare length-3 arrays which affect gate execution and measurement respectively. One or both can beNULLwhich indicates no noise is to be applied. -
libquil_error_t qvm_multishot_result_get(qvm_multishot_result qvm_result, char* region_name, int region_index, void* result)Get the measurement results forregion_indexinregion_name, storing the data in the pre-allocatedresultresultshould be a pointer to memory which has been allocated to storeNintegers, whereNis thetrialsvalue used forqvm_multishot. -
libquil_error_t qvm_multishot_measure(quil_program program, void* qubits, int n_qubits, int trials, void* result)Executeprogramon the QVMtrials-number of times, storing measurement results for the specifiedqubitsintoresultresultshould be a pointer to memory which has been allocated to storen_qubits * trialsintegers. This memory should be interpreted as the two-dimensional array whose outer dimension istrialsand whose inner dimension isn_qubits. -
libquil_error_t qvm_expectation(quil_program state_prep, void* operators, int n_operators, void* result)Calculate the expectation value<O|P|O>wherePis the provided state preparation programstate_prepandOis an operator, for eachOinoperators.resultshould be a pointer to memory that has been allocated to storen_operatorsdouble-precision floats. -
libquil_error_t qvm_wavefunction(quil_program program, void* result)Executeprogramon the QVM and return the associated wavefunctionresultshould be a pointer to memory that has been allocated to store2 * N_q^2double-precision floats whereN_qis the number of qubits used in the program. The factor of 2 is here to account for the fact that the wavefunction is a complex-valued vector, thus to represent it in C we need two values: one for the real part and one for the imaginary part.resultcan be interpreted as a two-dimensional array whose outer dimension (sizeN_q^2) is the wavefunction vector index, and whose inner dimension (size2) is the pair of values making up the complex value. -
libquil_error_t qvm_probabilities(quil_program program, void* results_ptr)Executeprogramon the QVM and return the wavefunction probabilitiesresultshould be a pointer to memory that has been allocated to storeN_q^2double-precision floats whereN_qis the number of qubits used in the program. Each indexiinresultis the probability of finding the wavefunction in the|i>state.
-
void lisp_release_handle(void* handle)Frees the Lisp-allocated memory forhandle -
int lisp_handle_eq(void* a, void* b)Compare Lisp object handles -
int init(char* core)Initialize the Lisp runtime using the providedcoreThis MUST be performed before using any of the above functions.