Global Namespace¶
Overview¶
// namespaces namespace Base64; namespace Eigen; namespace GATEGPU; namespace QGATE_SPACE; namespace QPanda; namespace QPanda::DRAW_TEXT_PIC; namespace QPanda::Variational; namespace gpu; namespace std; // typedefs typedef std::map<std::string, std::map<std::string, uint32_t>> config_map; typedef double qstate_type; typedef std::complex<qstate_type> qcomplex_t; typedef std::vector<qcomplex_t> QStat; typedef std::vector<size_t> Qnum; typedef std::vector<double> prob_vec; typedef std::unordered_map<std::string, qstate_type> prob_map; typedef std::unordered_map<std::string, qcomplex_t> stat_map; typedef std::map<std::string, double> prob_dict; typedef std::vector<std::pair<size_t, double>> prob_tuple; typedef std::shared_ptr<QPanda::QNode> QNodeRef; typedef wide_integer::generic_template::uint128_t uint128_t; typedef wide_integer::generic_template::uint256_t uint256_t; typedef wide_integer::generic_template::uint512_t uint512_t; typedef size_t gpu_qsize_t; typedef float gpu_qstate_t; typedef std::complex<gpu_qstate_t> gpu_qcomplex_t; typedef std::pair<size_t, double> gpu_pair; typedef std::vector<gpu_pair> touple_prob; typedef std::vector<double> vec_prob; typedef std::vector<gpu_qsize_t> Qnum; typedef Eigen::Matrix<qstate_type, Eigen::Dynamic, 1> rvector_t; typedef Eigen::Matrix<qcomplex_t, Eigen::Dynamic, 1> cvector_t; typedef Eigen::Matrix<qcomplex_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> cmatrix_t; typedef std::vector<QStat> NoiseOp; typedef bool (*noise_mode_function)( rapidjson::Value &, NoiseOp & ); typedef std::vector<QGateParam> vQParam; typedef size_t vertex_index_t; typedef std::vector<vertex_index_t> adj_arr_t; typedef std::map<vertex_index_t, adj_arr_t> graph_data_t; typedef float qdata_t; typedef size_t qsize_t; typedef std::complex<qdata_t> qcomplex_data_t; typedef std::vector<qcomplex_data_t> qstate_t; typedef std::vector<std::pair<size_t, bool>> qprog_sequence_t; typedef std::vector<std::pair<qsize_t, qsize_t>> qubit_vector_t; typedef std::map<size_t, Edge> edge_map_t; typedef std::map<qsize_t, Vertice> vertice_map_t; typedef std::vector<vertice_map_t> vertice_matrix_t; typedef struct QubitVertice qubit_vertice_t; // enums enum ComputeBackend; enum GateType; enum MetadataGateType; enum NOISE_MODEL; enum NodeType; enum OperatorType; enum Operatortype; enum QError; // structs struct Complex; struct QGateParam; struct QubitVertice; // classes class AbstractComplexTensor; class AbstractDistributedFullAmplitudeEngine; class AbstractQuantumGates; class CPUComplexTensor; class CPUImplQPU; class CPUImplQPUSingleThread; class CPUImplQPUSingleThreadWithOracle; class CPUImplQPUWithOracle; class ComplexTensor; class DefaultRandomEngine; class DeleteUnitQnode; class DistributedFullAmplitudeEngine; class DoubleGateNoiseModeMap; class Edge; class Instructions; class MPS_Tensor; class MeasureQVMType; class NoisyCPUImplQPU; class NoisyQuantum; class QPUImpl; class QProgMap; class QuantumError; class QuickBB; class RandomEngine; class RandomEngine19937; class ReadLock; class SharedMutex; class SingleGateNoiseModeMap; class TensorEngine; class Vertice; class VerticeMatrix; class WriteLock; class XC_RandomEngine16807; class originirBaseVisitor; class originirLexer; class originirListener; class originirParser; class originirVisitor; class qasmBaseVisitor; class qasmLexer; class qasmListener; class qasmParser; class qasmVisitor; // global variables const qstate_type PI = 3.14159265358979323846; constexpr qstate_type SQRT2 = 1.4142135623731; const gpu_qsize_t kThreadDim = 1024; // global functions uint32_t LOAD( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t STORE( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t BEQ( uint32_t rs1, uint32_t rs2, uint32_t imm ); uint32_t BNE( uint32_t rs1, uint32_t rs2, uint32_t imm ); uint32_t BLT( uint32_t rs1, uint32_t rs2, uint32_t imm ); uint32_t BGT( uint32_t rs1, uint32_t rs2, uint32_t imm ); uint32_t ADDI( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t ANDI( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t XORI( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t ORI( uint32_t rs1, uint32_t rd, uint32_t imm ); uint32_t ADD( uint32_t rs1, uint32_t rs2, uint32_t rd ); uint32_t AND( uint32_t rs1, uint32_t rs2, uint32_t rd ); uint32_t XOR( uint32_t rs1, uint32_t rs2, uint32_t rd ); uint32_t OR( uint32_t rs1, uint32_t rs2, uint32_t rd ); uint32_t QWAITI(uint32_t imm); uint32_t FMR( uint32_t rs1, uint32_t rd ); uint32_t SMIS( uint32_t rd, uint32_t imm ); uint32_t QI( uint32_t rs1, uint32_t rs2, uint32_t pi, uint32_t opcode1, uint32_t opcode2 ); uint32_t MEASURE( uint32_t rs1, uint32_t pi ); std::string _file_name(const char* file = ""); template <typename UnsignedIntegralType> std::string integerToBinary( const UnsignedIntegralType& number, int ret_len ); template <typename UnsignedIntegralType> std::string integerToString(const UnsignedIntegralType& number); template <typename UnsignedIntegralType> UnsignedIntegralType getDecIndex( const UnsignedIntegralType& num1, const UnsignedIntegralType& num2, std::vector<size_t> qvec, size_t len ); QStat matrix_multiply( const QStat& matrix_left, const QStat& matrix_right ); QStat matrix_tensor( const QStat& matrix_left, const QStat& matrix_right ); bool equal( const QStat& lhs, const QStat& rhs ); bool damping_kraus_operator ( rapidjson::Value&, NoiseOp& noise ); bool dephasing_kraus_operator ( rapidjson::Value&, NoiseOp& noise ); bool decoherence_kraus_operator ( rapidjson::Value&, NoiseOp& noise ); bool double_damping_kraus_operator ( rapidjson::Value&, NoiseOp& noise ); bool double_decoherence_kraus_operator ( rapidjson::Value&, NoiseOp& noise ); bool pauli_kraus_map( rapidjson::Value&, NoiseOp& noise ); bool decoherence_kraus_operator_p1_p2 ( rapidjson::Value& value, NoiseOp& noise ); bool bitflip_kraus_operator ( rapidjson::Value& value, NoiseOp& noise ); bool depolarizing_kraus_operator ( rapidjson::Value& value, NoiseOp& noise ); bool bit_phase_flip_operator (rapidjson::Value& value, NoiseOp& noise); bool phase_damping_oprator(rapidjson::Value& value, NoiseOp& noise); bool double_decoherence_kraus_operator_p1_p2 ( rapidjson::Value& value, NoiseOp& noise ); bool double_bitflip_kraus_operator ( rapidjson::Value& value, NoiseOp& noise ); bool double_depolarizing_kraus_operator ( rapidjson::Value& value, NoiseOp& noise ); bool double_bit_phase_flip_operator (rapidjson::Value& value, NoiseOp& noise); bool double_phase_damping_oprator(rapidjson::Value& value, NoiseOp& noise); bool kraus_matrix_oprator( rapidjson::Value& value, NoiseOp& noise ); double _default_random_generator(); double random_generator19937( double begine = 0, double end = 1 ); void H_Gate( qstate_t& gate_tensor, bool isDagger ); void T_Gate( qstate_t& gate_tensor, bool isDagger ); void S_Gate( qstate_t& gate_tensor, bool isDagger ); void X_Gate( qstate_t& gate_tensor, bool isDagger ); void Y_Gate( qstate_t& gate_tensor, bool isDagger ); void Z_Gate( qstate_t& gate_tensor, bool isDagger ); void X1_Gate( qstate_t& gate_tensor, bool isDagger ); void Y1_Gate( qstate_t& gate_tensor, bool isDagger ); void Z1_Gate( qstate_t& gate_tensor, bool isDagger ); void RX_Gate( qstate_t& gate_tensor, double angle, bool isDagger ); void RY_Gate( qstate_t& gate_tensor, double angle, bool isDagger ); void RZ_Gate( qstate_t& gate_tensor, double angle, bool isDagger ); void U1_Gate( qstate_t& gate_tensor, double angle, bool isDagger ); void U2_Gate( qstate_t& gate_tensor, double phi, double lambda, bool isDagger ); void U3_Gate( qstate_t& gate_tensor, double theta, double phi, double lambda, bool isDagger ); void U4_Gate( qstate_t& gate_tensor, double alpha, double beta, double gamma, double delta, bool isDagger ); void CZ_Gate( qstate_t& gate_tensor, bool isDagger ); void CNOT_Gate( qstate_t& gate_tensor, bool isDagger ); void ISWAP_Gate( qstate_t& gate_tensor, bool isDagger ); void SQISWAP_Gate( qstate_t& gate_tensor, bool isDagger ); void SWAP_Gate( qstate_t& gate_tensor, bool isDagger ); void CR_Gate( qstate_t& gate_tensor, double angle, bool isDagger ); void TOFFOLI_Gate( qstate_t& gate_tensor, bool isDagger ); DLLEXPORT ChemiQ* initialize(char* dir); DLLEXPORT void finalize(ChemiQ* chemiq); DLLEXPORT void setMolecule(ChemiQ* chemiq, char* molecule); DLLEXPORT void setMolecules(ChemiQ* chemiq, char* molecules); DLLEXPORT void setMultiplicity(ChemiQ* chemiq, int multiplicity); DLLEXPORT void setCharge(ChemiQ* chemiq, int charge); DLLEXPORT void setBasis(ChemiQ* chemiq, char* basis); DLLEXPORT void setEqTolerance(ChemiQ* chemiq, double val); DLLEXPORT void setTransformType(ChemiQ* chemiq, int type); DLLEXPORT void setUccType(ChemiQ* chemiq, int type); DLLEXPORT void setOptimizerType(ChemiQ* chemiq, int type); DLLEXPORT void setOptimizerIterNum(ChemiQ* chemiq, int value); DLLEXPORT void setOptimizerFuncCallNum(ChemiQ* chemiq, int value); DLLEXPORT void setOptimizerXatol(ChemiQ* chemiq, double value); DLLEXPORT void setOptimizerFatol(ChemiQ* chemiq, double value); DLLEXPORT void setLearningRate(ChemiQ* chemiq, double value); DLLEXPORT void setEvolutionTime(ChemiQ* chemiq, double value); DLLEXPORT void setHamiltonianSimulationSlices(ChemiQ* chemiq, int value); DLLEXPORT void setSaveDataDir(ChemiQ* chemiq, char* dir); DLLEXPORT int getQubitsNum(ChemiQ* chemiq); DLLEXPORT bool exec(ChemiQ* chemiq); const DLLEXPORT char* getLastError(ChemiQ* chemiq); // macros #define ANGLE_VAR_BASE #define COMPENSATE_ANGLE #define CONFIG_PATH #define CONST_GATE(NAME) #define CONTROL_CONST_GATE(NAME) #define CONTROL_SINGLE_ANGLE_GATE(NAME) #define DECL_ANGLE_GATE_MATRIX(NAME) #define DECL_GATE_MATRIX(NAME) #define DEFAULT_THREAD_CNT #define DOUBLE_GATE_TIME #define DoubleGateMatrixSize #define GATE_BARRIER #define GATE_CNOT #define GATE_CPHASE #define GATE_CU #define GATE_CZ #define GATE_ECHO #define GATE_H #define GATE_I #define GATE_ISWAP #define GATE_ISWAPTheta #define GATE_QDoubleGate #define GATE_RPHI #define GATE_RX #define GATE_RY #define GATE_RZ #define GATE_S #define GATE_SQISWAP #define GATE_SWAP #define GATE_T #define GATE_TYPE_MEASURE #define GATE_TYPE_READOUT #define GATE_TYPE_RESET #define GATE_U1 #define GATE_U2 #define GATE_U3 #define GATE_U4 #define GATE_X #define GATE_X1 #define GATE_Y #define GATE_Y1 #define GATE_Z #define GATE_Z1 #define HIGH_FREQUENCY_QUBIT #define INF #define INF #define INF #define KMETADATA_GATE_TYPE_COUNT #define MACRO_GET_GATETYPE(name) #define MAX_COMPARE_PRECISION #define MAX_LAYER #define MAX_THREADS #define PI #define PI #define PI #define PI #define PI #define PRINT_TRACE #define PRINT_TRACE #define PRINT_TRACE #define PRINT_TRACE #define PRINT_TRACE #define PRINT_TRACE #define QCERR(x) #define QCERR_AND_THROW( \ std_exception, \ _Message_ \ ) #define QCERR_AND_THROW_ERRSTR( \ std_exception, \ x \ ) #define QCIRCUIT_OPTIMIZER #define QIF_REGISTER(className) #define QPANDA_ASSERT( \ con, \ argv \ ) #define QPANDA_BEGIN #define QPANDA_END #define QPANDA_MAJOR_VERSION #define QPANDA_MINOR_VERSION #define QPANDA_OP( \ con, \ op \ ) #define QPANDA_PATCH_VERSION #define QPANDA_RETURN( \ con, \ value \ ) #define QUBIT_ADJACENT_MATRIX #define QWHILE_REGISTER(className) #define REGISTER_ANGLE_GATE_MATRIX( \ NAME, \ Nx, \ Ny, \ Nz \ ) #define REGISTER_CBIT_NAME_(classname) #define REGISTER_CEXPR(classname) #define REGISTER_CLASSICAL_PROGRAM(className) #define REGISTER_CMEM_SIZE_(classname) #define REGISTER_GATE_MATRIX( \ NAME, \ U00, \ U01, \ U10, \ U11 \ ) #define REGISTER_MEASURE(className) #define REGISTER_PHYSICAL_QUBIT(classname) #define REGISTER_QCIRCUIT(className) #define REGISTER_QPROGRAM(className) #define REGISTER_QRES_NAME(classname) #define REGISTER_QUANTUM_MACHINE(classname) #define REGISTER_QUBIT(classname) #define REGISTER_QUBIT_POOL_SIZE_(classname) #define REGISTER_RESET(className) #define SAFE_DELETE_PTR(p) #define SINGLETON_DECLARE(Type) #define SINGLETON_IMPLEMENT_EAGER(Type) #define SINGLETON_IMPLEMENT_LAZY(Type) #define SINGLE_ANGLE_GATE(NAME) #define SINGLE_GATE_TIME #define SQ2 #define SQ2 #define SQ2 #define SWAP_TIME #define SingleGateMatrixSize #define UNDEF_DOUBLE #define USING_QPANDA #define VIRTUAL_Z_CONFIG #define ZeroJudgement #define _DOUBLE_ANGLE_GATE(NAME) #define _DOUBLE_GATE(NAME) #define _SINGLE_ANGLE_GATE(NAME) #define _SINGLE_GATE(NAME) #define _TRIPLE_GATE(NAME) #define __FILENAME__ #define const_single_qubit_gate( \ GATE_NAME, \ qn, \ isConjugate, \ error_rate \ ) #define control_const_single_qubit_gate( \ GATE_NAME, \ qn, \ vControlBit, \ isConjugate, \ error_rate \ ) #define control_single_qubit_angle_gate( \ GATE_NAME, \ qn, \ theta, \ vControlBit, \ isConjugate, \ error_rate \ ) #define iunit #define single_qubit_angle_gate( \ GATE_NAME, \ qn, \ theta, \ isConjugate, \ error_rate \ )
Detailed Documentation¶
Global Functions¶
template <typename UnsignedIntegralType> std::string integerToBinary( const UnsignedIntegralType& number, int ret_len )
Unsigned integer to binary string.
Parameters:
const |
UnsignedIntegralType & number |
int |
binary string length |
Returns:
std::string unsigned integer string
template <typename UnsignedIntegralType> std::string integerToString(const UnsignedIntegralType& number)
Unsigned integer to binary string.
Parameters:
const |
UnsignedIntegralType & number |
Returns:
std::string unsigned integer string
template <typename UnsignedIntegralType> UnsignedIntegralType getDecIndex( const UnsignedIntegralType& num1, const UnsignedIntegralType& num2, std::vector<size_t> qvec, size_t len )
Get quantum state dec index in pmeasure.
Parameters:
const |
UnsignedIntegralType & num1 |
const |
UnsignedIntegralType & num2 |
std::vector<size_t> |
qvec |
size_t |
binary string length |
Returns:
Unsigned Integral Type
DLLEXPORT ChemiQ* initialize(char* dir)
Initialize the quantum chemistry calculation.
Parameters:
std::string |
The dir of the psi4 chemistry calculation package |
Returns:
ChemiQ* a ChemiQ object ptr
DLLEXPORT void finalize(ChemiQ* chemiq)
Finalize the quantum chemistry calculation.
Parameters:
ChemiQ* |
the ChemiQ object ptr will be finalized |
DLLEXPORT void setMolecule(ChemiQ* chemiq, char* molecule)
Set the molecular model to calculate.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
std::string |
molecule model |
DLLEXPORT void setMolecules(ChemiQ* chemiq, char* molecules)
Set the molecular model to calculate.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
char* |
the molecules ptr |
DLLEXPORT void setMultiplicity(ChemiQ* chemiq, int multiplicity)
Set the multiplicity of the molecular model.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
int |
multiplicity |
DLLEXPORT void setCharge(ChemiQ* chemiq, int charge)
Set the charge of the molecular model.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
int |
charge |
DLLEXPORT void setBasis(ChemiQ* chemiq, char* basis)
Set the calculation basis.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
std::string |
basis |
DLLEXPORT void setEqTolerance(ChemiQ* chemiq, double val)
Set Eq Tolerance.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
double |
EqTolerance value |
DLLEXPORT void setTransformType(ChemiQ* chemiq, int type)
Set the transform type from Fermion operator to Pauli operator.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
int |
transform type |
See also:
QPanda::TransFormType
DLLEXPORT void setUccType(ChemiQ* chemiq, int type)
Set the ucc type to contruct the Fermion operator.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
int |
ucc type |
See also:
QPanda::UccType
DLLEXPORT void setOptimizerType(ChemiQ* chemiq, int type)
Set the optimizer type.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
int |
optimizer type |
See also:
QPanda::OptimizerType
DLLEXPORT void setOptimizerIterNum(ChemiQ* chemiq, int value)
Set the optimizer iteration number.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
size_t |
iteration number |
DLLEXPORT void setOptimizerFuncCallNum(ChemiQ* chemiq, int value)
Set the optimizer function callback number.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
size_t |
function callback number |
DLLEXPORT void setOptimizerXatol(ChemiQ* chemiq, double value)
Set the optimizer iteration number.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
size_t |
iteration number |
DLLEXPORT void setOptimizerFatol(ChemiQ* chemiq, double value)
Set the optimizer fatol.It is the Absolute error in func(xopt) between iterations that is acceptable for convergence.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
double |
absolute error between func(xopt) |
DLLEXPORT void setLearningRate(ChemiQ* chemiq, double value)
Set the learing rate when using Gradient optimizer.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
double |
learing rate |
DLLEXPORT void setEvolutionTime(ChemiQ* chemiq, double value)
Set the evolution time when doing hamiltonian simulation.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
double |
evolution time |
DLLEXPORT void setHamiltonianSimulationSlices(ChemiQ* chemiq, int value)
Set the hamiltonian simulation slices (e^iAt/n*e^iBt/n)^n, n is the slices.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
double |
hamiltonian simulation slices |
DLLEXPORT void setSaveDataDir(ChemiQ* chemiq, char* dir)
Set the directory to save the calculated data. If it’s a not exist dir data will not be saved.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
std::string |
dir |
DLLEXPORT int getQubitsNum(ChemiQ* chemiq)
get qubits num with the above config.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
Returns:
int -1:means failed.
DLLEXPORT bool exec(ChemiQ* chemiq)
exec molecule calculate.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
Returns:
bool true:success; false:failed
const DLLEXPORT char* getLastError(ChemiQ* chemiq)
get last error.
Parameters:
ChemiQ* |
the target ChemiQ object ptr |
Returns:
char* last error
Macros¶
#define QCERR(x)
QPanda2 cout error message.
#define QCERR_AND_THROW_ERRSTR(std_exception, x)
output the error string to standard error and throw a standard exception. A standard exception can be of the following types: runtime_error, invalid_argument, range_error, etc