Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Classes | Macros | Functions | Variables
qgd_N_Qubit_Decomposition_Wrapper.cpp File Reference
#include <Python.h>
#include <numpy/arrayobject.h>
#include "structmember.h"
#include <stdio.h>
#include "N_Qubit_Decomposition.h"
#include "numpy_interface.h"
Include dependency graph for qgd_N_Qubit_Decomposition_Wrapper.cpp:

Go to the source code of this file.

Classes

struct  qgd_Circuit_Wrapper
 Type definition of the qgd_Circuit_Wrapper Python class of the qgd_Circuit_Wrapper module. More...
 
struct  qgd_N_Qubit_Decomposition_Wrapper
 Type definition of the qgd_N_Qubit_Decomposition_Wrapper Python class of the qgd_N_Qubit_Decomposition_Wrapper module. More...
 

Macros

#define PY_SSIZE_T_CLEAN
 

Functions

N_Qubit_Decompositioncreate_N_Qubit_Decomposition (Matrix &Umtx, int qbit_num, bool optimize_layer_num, std::map< std::string, Config_Element > &config, guess_type initial_guess)
 Creates an instance of class N_Qubit_Decomposition and return with a pointer pointing to the class instance (C++ linking is needed) More...
 
PyMODINIT_FUNC PyInit_qgd_N_Qubit_Decomposition_Wrapper (void)
 Method called when the Python module is initialized. More...
 
static void qgd_N_Qubit_Decomposition_Wrapper_dealloc (qgd_N_Qubit_Decomposition_Wrapper *self)
 Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is destroyed. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_get_circuit (qgd_N_Qubit_Decomposition_Wrapper *self)
 Wrapper function to retrieve the circuit (Squander format) incorporated in the instance. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_get_gate_num (qgd_N_Qubit_Decomposition_Wrapper *self)
 Wrapper function to get the number of decomposing gates. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_get_Optimized_Parameters (qgd_N_Qubit_Decomposition_Wrapper *self)
 Extract the optimized parameters. More...
 
static int qgd_N_Qubit_Decomposition_Wrapper_init (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args, PyObject *kwds)
 Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is initialized. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_List_Gates (qgd_N_Qubit_Decomposition_Wrapper *self)
 Lists the gates decomposing the initial unitary. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is allocated. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_Reorder_Qubits (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Wrapper method to reorder the qubits in the decomposition class. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Convergence_Threshold (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Wrapper method to set the threshold of convergence in the optimization processes. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Debugfile (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Set the debugfile name of the N_Qubit_Decomposition class. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Gate_Structure (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Wrapper function to set custom gate structure for the decomposition. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Identical_Blocks (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Set the number of identical successive blocks during the subdecomposition of the qbit-th qubit. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Iteration_Loops (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Set the number of iteration loops during the subdecomposition of the qbit-th qubit. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Max_Layer_Num (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Set the maximal number of layers used in the subdecomposition of the qbit-th qubit. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Blocks (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Wrapper method to to set the number of gate blocks to be optimized in one shot. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Tolerance (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Wrapper method to set the optimization tolerance of the optimization process during the decomposition. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_set_Verbose (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args)
 Set the verbosity of the N_Qubit_Decomposition class. More...
 
static PyObject * qgd_N_Qubit_Decomposition_Wrapper_Start_Decomposition (qgd_N_Qubit_Decomposition_Wrapper *self, PyObject *args, PyObject *kwds)
 Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition. More...
 
void release_N_Qubit_Decomposition (N_Qubit_Decomposition *instance)
 Call to deallocate an instance of N_Qubit_Decomposition class. More...
 

Variables

static PyMemberDef qgd_N_Qubit_Decomposition_Wrapper_members []
 Structure containing metadata about the members of class qgd_N_Qubit_Decomposition_Wrapper. More...
 
static PyMethodDef qgd_N_Qubit_Decomposition_Wrapper_methods []
 Structure containing metadata about the methods of class qgd_N_Qubit_Decomposition_Wrapper. More...
 
static PyModuleDef qgd_N_Qubit_Decomposition_Wrapper_Module
 Structure containing metadata about the module. More...
 
static PyTypeObject qgd_N_Qubit_Decomposition_Wrapper_Type
 A structure describing the type of the class qgd_N_Qubit_Decomposition_Wrapper. More...
 

Macro Definition Documentation

◆ PY_SSIZE_T_CLEAN

#define PY_SSIZE_T_CLEAN

Definition at line 27 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Function Documentation

◆ create_N_Qubit_Decomposition()

N_Qubit_Decomposition* create_N_Qubit_Decomposition ( Matrix Umtx,
int  qbit_num,
bool  optimize_layer_num,
std::map< std::string, Config_Element > &  config,
guess_type  initial_guess 
)

Creates an instance of class N_Qubit_Decomposition and return with a pointer pointing to the class instance (C++ linking is needed)

Parameters
UmtxAn instance of class Matrix containing the unitary to be decomposed
qbit_numNumber of qubits spanning the unitary
optimize_layer_numLogical value. Set true to optimize the number of decomposing layers during the decomposition procedure, or false otherwise.
initial_guessType to guess the initial values for the optimization. Possible values: ZEROS=0, RANDOM=1, CLOSE_TO_ZERO=2
Returns
Return with a void pointer pointing to an instance of N_Qubit_Decomposition class.

Definition at line 74 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the caller graph for this function:

◆ PyInit_qgd_N_Qubit_Decomposition_Wrapper()

PyMODINIT_FUNC PyInit_qgd_N_Qubit_Decomposition_Wrapper ( void  )

Method called when the Python module is initialized.

Definition at line 874 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_dealloc()

static void qgd_N_Qubit_Decomposition_Wrapper_dealloc ( qgd_N_Qubit_Decomposition_Wrapper self)
static

Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is destroyed.

Parameters
selfA pointer pointing to an instance of class qgd_N_Qubit_Decomposition_Wrapper.

Definition at line 104 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the call graph for this function:

◆ qgd_N_Qubit_Decomposition_Wrapper_get_circuit()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_get_circuit ( qgd_N_Qubit_Decomposition_Wrapper self)
static

Wrapper function to retrieve the circuit (Squander format) incorporated in the instance.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_custom_Wrapper.

Definition at line 276 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the call graph for this function:

◆ qgd_N_Qubit_Decomposition_Wrapper_get_gate_num()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_get_gate_num ( qgd_N_Qubit_Decomposition_Wrapper self)
static

Wrapper function to get the number of decomposing gates.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
Returns
Returns with the number of gates

Definition at line 257 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_get_Optimized_Parameters()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_get_Optimized_Parameters ( qgd_N_Qubit_Decomposition_Wrapper self)
static

Extract the optimized parameters.

Parameters
start_indexThe index of the first inverse gate

Definition at line 336 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the call graph for this function:

◆ qgd_N_Qubit_Decomposition_Wrapper_init()

static int qgd_N_Qubit_Decomposition_Wrapper_init ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args,
PyObject *  kwds 
)
static

Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is initialized.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: Umtx (numpy array), qbit_num (integer), optimize_layer_num (bool), initial_guess (string PyObject
kwdsA tuple of keywords

Definition at line 148 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the call graph for this function:

◆ qgd_N_Qubit_Decomposition_Wrapper_List_Gates()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_List_Gates ( qgd_N_Qubit_Decomposition_Wrapper self)
static

Lists the gates decomposing the initial unitary.

(These gates are the inverse gates of the gates bringing the intial matrix into unity.)

Parameters
start_indexThe index of the first inverse gate

Definition at line 321 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_new()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_new ( PyTypeObject type,
PyObject *  args,
PyObject *  kwds 
)
static

Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is allocated.

Parameters
typeA pointer pointing to a structure describing the type of the class qgd_N_Qubit_Decomposition_Wrapper.

Definition at line 128 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_Reorder_Qubits()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_Reorder_Qubits ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Wrapper method to reorder the qubits in the decomposition class.

Parameters

Definition at line 677 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Convergence_Threshold()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Convergence_Threshold ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Wrapper method to set the threshold of convergence in the optimization processes.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: tolerance (double) tolerance: The maximal allowed error of the optimization problem

Definition at line 580 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Debugfile()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Debugfile ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Set the debugfile name of the N_Qubit_Decomposition class.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_adaptive_Wrapper.
argsA tuple of the input arguments: debugfile_name (string) debug: Set True to suppress the output messages of the decompostion into a file named debugfile_name, or False (deafult) otherwise.

Definition at line 522 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Gate_Structure()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Gate_Structure ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Wrapper function to set custom gate structure for the decomposition.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: gate_structure_dict (PyDict) gate_structure_dict: ?????????????????????????????
Returns
Returns with zero on success.

Definition at line 629 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Identical_Blocks()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Identical_Blocks ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Set the number of identical successive blocks during the subdecomposition of the qbit-th qubit.

Parameters
identical_blocksA dictionary {'n': identical_blocks} labeling the number of successive identical layers used in the subdecomposition at the disentangling of the n-th qubit.

Definition at line 406 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Iteration_Loops()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Iteration_Loops ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Set the number of iteration loops during the subdecomposition of the qbit-th qubit.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: identical_blocks (PyDict) identical_blocks: A dictionary {'n': iteration_loops} labeling the number of successive identical layers used in the subdecomposition at the disentangling of the n-th qubit.

Definition at line 454 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Max_Layer_Num()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Max_Layer_Num ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Set the maximal number of layers used in the subdecomposition of the qbit-th qubit.

Parameters
max_layer_numA dictionary {'n': max_layer_num} labeling the maximal number of the gate layers used in the subdecomposition.

Definition at line 361 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Blocks()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Blocks ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Wrapper method to to set the number of gate blocks to be optimized in one shot.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: tolerance (double) optimization_block: number of operators in one sub-layer of the optimization process

Definition at line 604 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Tolerance()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Optimization_Tolerance ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Wrapper method to set the optimization tolerance of the optimization process during the decomposition.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: tolerance (double) tolerance: The maximal allowed error of the optimization problem

Definition at line 557 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_set_Verbose()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_set_Verbose ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args 
)
static

Set the verbosity of the N_Qubit_Decomposition class.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
argsA tuple of the input arguments: verbose (int) verbose: Set False to suppress the output messages of the decompostion, or True (deafult) otherwise.

Definition at line 500 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_Start_Decomposition()

static PyObject* qgd_N_Qubit_Decomposition_Wrapper_Start_Decomposition ( qgd_N_Qubit_Decomposition_Wrapper self,
PyObject *  args,
PyObject *  kwds 
)
static

Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition.

Parameters
selfA pointer pointing to an instance of the class qgd_N_Qubit_Decomposition_Wrapper.
kwdsA tuple of keywords

Definition at line 227 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ release_N_Qubit_Decomposition()

void release_N_Qubit_Decomposition ( N_Qubit_Decomposition instance)

Call to deallocate an instance of N_Qubit_Decomposition class.

Parameters
ptrA pointer pointing to an instance of N_Qubit_Decomposition class.

Definition at line 85 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ qgd_N_Qubit_Decomposition_Wrapper_members

PyMemberDef qgd_N_Qubit_Decomposition_Wrapper_members[]
static
Initial value:
= {
{NULL}
}

Structure containing metadata about the members of class qgd_N_Qubit_Decomposition_Wrapper.

Definition at line 731 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_methods

PyMethodDef qgd_N_Qubit_Decomposition_Wrapper_methods[]
static

Structure containing metadata about the methods of class qgd_N_Qubit_Decomposition_Wrapper.

Definition at line 738 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_Module

PyModuleDef qgd_N_Qubit_Decomposition_Wrapper_Module
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"qgd_N_Qubit_Decomposition_Wrapper",
"Python binding for QGD N_Qubit_Decomposition class",
-1,
}

Structure containing metadata about the module.

Definition at line 862 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.

◆ qgd_N_Qubit_Decomposition_Wrapper_Type

PyTypeObject qgd_N_Qubit_Decomposition_Wrapper_Type
static

A structure describing the type of the class qgd_N_Qubit_Decomposition_Wrapper.

Definition at line 790 of file qgd_N_Qubit_Decomposition_Wrapper.cpp.