115 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
135 if ( idx>= (
int)
gates.size() )
return;
175 std::stringstream sstream;
180 apply_to(parameters, block_mtx, parallel);
183 if (block_mtx.
isnan()) {
184 std::stringstream sstream;
185 sstream <<
"Gates_block::get_matrix: block_mtx contains NaN." << std::endl;
206 if ( parallel == 0 ) {
207 work_batch = inputs.size();
214 tbb::parallel_for( tbb::blocked_range<int>(0,inputs.size(),work_batch), [&](tbb::blocked_range<int> r) {
215 for (
int idx=r.begin(); idx<r.end(); ++idx) {
217 Matrix* input = &inputs[idx];
219 apply_to( parameters_mtx, *input, parallel );
241 std::string err(
"Gates_block::apply_to: Wrong input size in Gates_block gate apply.");
249 std::string error(
"Gates_block::apply_to: GATE fusion has not been adopted to reversed parameter ordering!!!!!!!!!!!!!!!!!!!");
258 int outer_idx =
gates.size()-1;
259 for (
int block_idx=0; block_idx<
involved_qbits.size(); block_idx++){
266 int* indices = (
int*)_malloca(
qbit_num*
sizeof(
int));
271 for (
int jdx=0; jdx<(
int)qbits.size(); jdx++){
272 indices[qbits[jdx]]=jdx;
275 for (
int idx=outer_idx; idx>=
block_end[block_idx]; idx--){
280 int target_qubit_new = indices[trgt_qbit];
283 int control_qubit_new = (ctrl_qbit==-1) ? -1:indices[ctrl_qbit];
292 gates_block_mini.
apply_to(parameters_mtx, Umtx_mini);
299 apply_large_kernel_to_state_vector_input(Umtx_mini, input, qbits, input.
size() );
308 for (
int idx=outer_idx;idx>=0;idx--){
314 gates_block_mini.
apply_to(parameters_mtx, input);
318 else if ( involved_qubits.size() == 1 &&
gates.size() > 1 &&
qbit_num > 1 ) {
323 for (
int idx=0; idx<
gates.size(); idx++){
335 gates_block_mini.
apply_to(parameters_mtx_loc, Umtx_mini);
343 for(
int idx=0; idx<
gates.size(); idx++) {
350 operation->
apply_to(input, parallel);
353 operation->
apply_to( parameters_mtx_loc, input, parallel );
357 std::stringstream sstream;
358 sstream <<
"Gates_block::apply_to: transformed matrix contains NaN." << std::endl;
380 bool is_qbit_present(std::vector<int> involved_qubits,
int new_qbit,
int num_of_qbits){
382 bool contained=
false;
384 for (
int idx=0; idx<num_of_qbits; idx++) {
386 if(involved_qubits[idx] == new_qbit) {
401 std::vector<int> qbits;
405 for (
int idx =
gates.size()-1; idx>=0; idx--){
411 if (num_of_qbits == 0) {
412 qbits.push_back(target_new);
417 bool target_contained =
is_qbit_present(qbits,target_new,num_of_qbits);
418 bool control_contained = (control_new==-1) ?
true :
is_qbit_present(qbits, control_new, num_of_qbits);
420 if (num_of_qbits == max_fusion_temp && (target_contained ==
false || control_contained ==
false)){
423 while(vidx<num_of_qbits){
426 while(jdx>0 && qbits[jdx-1]>qbits[jdx]){
427 int qbit_temp = qbits[jdx];
428 qbits[jdx] = qbits[jdx-1];
429 qbits[jdx-1] = qbit_temp;
441 qbits=std::vector<int>{};
446 if (num_of_qbits<max_fusion_temp && target_contained==
false){
447 qbits.push_back(target_new);
451 if (num_of_qbits<max_fusion_temp && control_contained==
false){
452 qbits.push_back(control_new);
459 if (num_of_qbits == 1){
467 while(vidx<num_of_qbits){
470 while(jdx>0 && qbits[jdx-1]>qbits[jdx]){
471 int qbit_temp = qbits[jdx];
472 qbits[jdx] = qbits[jdx-1];
473 qbits[jdx-1] = qbit_temp;
495 for(
int op_idx = 0; op_idx<
gates.size(); op_idx++) {
501 parameter_idx = parameter_idx + 1;
506 data[parameter_idx+1] = 2 * M_PI;
507 parameter_idx = parameter_idx + 2;
512 data[parameter_idx+1] = 2 * M_PI;
513 data[parameter_idx+2] = 2 * M_PI;
514 parameter_idx = parameter_idx + 3;
520 data[parameter_idx-1] = 4*M_PI;
521 data[parameter_idx-2] = 2*M_PI;
522 parameter_idx = parameter_idx - 2;
529 parameter_idx = parameter_idx + 1;
533 parameter_idx = parameter_idx + 1;
543 data[parameter_idx+i] = 2 * M_PI;
561 std::stringstream sstream;
566 int parameters_num_total = 0;
567 for (
int idx=0; idx<
gates.size(); idx++) {
580 for(
int idx=0; idx<(
int)
gates.size(); idx++) {
595 U1* u1_operation =
static_cast<U1*
>(operation);
600 U2* u2_operation =
static_cast<U2*
>(operation);
605 U3* u3_operation =
static_cast<U3*
>(operation);
610 R* r_operation =
static_cast<R*
>(operation);
615 RX* rx_operation =
static_cast<RX*
>(operation);
620 RY* ry_operation =
static_cast<RY*
>(operation);
625 CRY* cry_operation =
static_cast<CRY*
>(operation);
630 CR* cr_operation =
static_cast<CR*
>(operation);
635 RZ* rz_operation =
static_cast<RZ*
>(operation);
640 UN* un_operation =
static_cast<UN*
>(operation);
645 ON* on_operation =
static_cast<ON*
>(operation);
655 CZ_NU* cz_nu_operation =
static_cast<CZ_NU*
>(operation);
670 std::string err(
"Gates_block::apply_from_right: unimplemented gate");
678 std::stringstream sstream;
679 sstream <<
"Gates_block::apply_from_right: transformed matrix contains NaN." << std::endl;
701 std::stringstream sstream;
706 if ( parallel == 0 ) {
707 work_batch =
gates.size();
715 tbb::parallel_for( tbb::blocked_range<int>(0,
gates.size(),work_batch), [&](tbb::blocked_range<int> r) {
716 for (
int deriv_idx=r.begin(); deriv_idx<r.end(); ++deriv_idx) {
734 std::vector<Matrix> grad_loc;
736 for(
int idx=0; idx<
gates.size(); idx++) {
749 std::string err(
"Gates_block::apply_derivate_to: Given operation not supported in gardient calculation");
757 if( idx < deriv_idx ) {
758 operation->
apply_to( input_loc, parallel );
767 if( idx < deriv_idx ) {
768 operation->
apply_to( parameters_mtx, input_loc, parallel );
770 else if ( idx == deriv_idx ) {
774 operation->
apply_to_list(parameters_mtx, grad_loc, parallel );
783 for (
int idx = 0; idx<(
int)grad_loc.size(); idx++ ) {
784 grad[deriv_parameter_idx+idx] = grad_loc[idx];
1471 for(std::vector<Gate*>::iterator it = gates_in.begin(); it != gates_in.end(); ++it) {
1485 for(std::vector<Gate*>::iterator it = gates_in.end(); it != gates_in.begin(); --it) {
1617 gates.push_back(gate);
1701 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
1712 std::string gate_name = gate->
get_name();
1714 if( gate_nums.find(gate_name) == gate_nums.end() ) {
1715 gate_nums[ gate_name ] = 1;
1718 gate_nums[ gate_name ] = gate_nums[ gate_name ] + 1;
1733 std::map<std::string, int> gate_nums;
1758 return gates.size();
1771 std::stringstream sstream;
1772 sstream << std::endl <<
"The gates in the list of gates:" << std::endl;
1775 int gate_idx = start_index;
1777 double *parameters_data = parameters.
get_data();
1781 for(
int op_idx = 0; op_idx<
gates.size(); op_idx++) {
1786 CNOT* cnot_gate =
static_cast<CNOT*
>(gate);
1787 std::stringstream sstream;
1788 sstream << gate_idx <<
"th gate: CNOT with control qubit: " << cnot_gate->
get_control_qbit() <<
" and target qubit: " << cnot_gate->
get_target_qbit() << std::endl;
1790 gate_idx = gate_idx + 1;
1793 CROT* crot_gate =
static_cast<CROT*
>(gate);
1794 std::stringstream sstream;
1796 theta0 = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1797 phi0 = std::fmod( parameters_data[parameter_idx+1], 2*M_PI);
1798 parameter_idx = parameter_idx + 2;
1799 sstream << gate_idx <<
"th gate: CROT with control qubit: " << crot_gate->
get_control_qbit() <<
" and target qubit: " << crot_gate->
get_target_qbit()<<
" and parameters theta=" << theta0 <<
" and phi="<< phi0 << std::endl;
1801 gate_idx = gate_idx + 1;
1804 CZ* cz_gate =
static_cast<CZ*
>(gate);
1805 std::stringstream sstream;
1806 sstream << gate_idx <<
"th gate: CZ with control qubit: " << cz_gate->
get_control_qbit() <<
" and target qubit: " << cz_gate->
get_target_qbit() << std::endl;
1808 gate_idx = gate_idx + 1;
1811 CH* ch_gate =
static_cast<CH*
>(gate);
1812 std::stringstream sstream;
1813 sstream << gate_idx <<
"th gate: CH with control qubit: " << ch_gate->
get_control_qbit() <<
" and target qubit: " << ch_gate->
get_target_qbit() << std::endl;
1815 gate_idx = gate_idx + 1;
1818 SYC* syc_gate =
static_cast<SYC*
>(gate);
1819 std::stringstream sstream;
1820 sstream << gate_idx <<
"th gate: Sycamore gate with control qubit: " << syc_gate->
get_control_qbit() <<
" and target qubit: " << syc_gate->
get_target_qbit() << std::endl;
1822 gate_idx = gate_idx + 1;
1825 U1* u1_gate =
static_cast<U1*
>(gate);
1826 double lambda = std::fmod(parameters_data[parameter_idx], 2*M_PI);
1827 parameter_idx = parameter_idx + 1;
1828 std::stringstream sstream;
1829 sstream << gate_idx <<
"th gate: U1 on target qubit: " << u1_gate->
get_target_qbit() <<
" with parameter lambda = " << lambda << std::endl;
1831 gate_idx = gate_idx + 1;
1834 U2* u2_gate =
static_cast<U2*
>(gate);
1835 double phi = std::fmod(parameters_data[parameter_idx], 2*M_PI);
1836 double lambda = std::fmod(parameters_data[parameter_idx+1], 2*M_PI);
1837 parameter_idx = parameter_idx + 2;
1838 std::stringstream sstream;
1839 sstream << gate_idx <<
"th gate: U2 on target qubit: " << u2_gate->
get_target_qbit() <<
" with parameters phi = " << phi <<
" and lambda = " << lambda << std::endl;
1841 gate_idx = gate_idx + 1;
1844 U3* u3_gate =
static_cast<U3*
>(gate);
1845 double theta = std::fmod(parameters_data[parameter_idx], 4*M_PI);
1846 double phi = std::fmod(parameters_data[parameter_idx+1], 2*M_PI);
1847 double lambda = std::fmod(parameters_data[parameter_idx+2], 2*M_PI);
1848 parameter_idx = parameter_idx + 3;
1849 std::stringstream sstream;
1850 sstream << gate_idx <<
"th gate: U3 on target qubit: " << u3_gate->
get_target_qbit() <<
" with parameters theta = " << theta <<
", phi = " << phi <<
" and lambda = " << lambda << std::endl;
1852 gate_idx = gate_idx + 1;
1856 double vartheta,varphi;
1858 R* r_gate =
static_cast<R*
>(gate);
1859 vartheta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1860 varphi = std::fmod( parameters_data[parameter_idx+1], 2*M_PI);
1861 parameter_idx = parameter_idx + 2;
1863 std::stringstream sstream;
1864 sstream << gate_idx <<
"th gate: R on target qubit: " << r_gate->
get_target_qbit() <<
" and with parameters theta = " << vartheta <<
" and phi:" << varphi << std::endl;
1866 gate_idx = gate_idx + 1;
1872 RX* rx_gate =
static_cast<RX*
>(gate);
1873 vartheta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1874 parameter_idx = parameter_idx + 1;
1876 std::stringstream sstream;
1877 sstream << gate_idx <<
"th gate: RX on target qubit: " << rx_gate->
get_target_qbit() <<
" and with parameters theta = " << vartheta << std::endl;
1879 gate_idx = gate_idx + 1;
1885 RY* ry_gate =
static_cast<RY*
>(gate);
1886 vartheta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1887 parameter_idx = parameter_idx + 1;
1889 std::stringstream sstream;
1890 sstream << gate_idx <<
"th gate: RY on target qubit: " << ry_gate->
get_target_qbit() <<
" and with parameters theta = " << vartheta << std::endl;
1892 gate_idx = gate_idx + 1;
1898 CRY* cry_gate =
static_cast<CRY*
>(gate);
1899 vartheta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1900 parameter_idx = parameter_idx + 1;
1902 std::stringstream sstream;
1903 sstream << gate_idx <<
"th gate: CRY on target qubit: " << cry_gate->
get_target_qbit() <<
", control qubit" << cry_gate->
get_control_qbit() <<
" and with parameters theta = " << vartheta << std::endl;
1905 gate_idx = gate_idx + 1;
1909 double vartheta,varphi;
1911 CR* cr_gate =
static_cast<CR*
>(gate);
1912 vartheta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
1913 varphi = std::fmod(parameters_data[parameter_idx+1],2*M_PI);
1914 parameter_idx = parameter_idx + 2;
1916 std::stringstream sstream;
1917 sstream << gate_idx <<
"th gate: CR on target qubit: " << cr_gate->
get_target_qbit() <<
", control qubit" << cr_gate->
get_control_qbit() <<
" and with parameters theta and phi = " << vartheta <<
" , " << varphi << std::endl;
1919 gate_idx = gate_idx + 1;
1925 RZ* rz_gate =
static_cast<RZ*
>(gate);
1926 varphi = std::fmod( 2*parameters_data[parameter_idx], 2*M_PI);
1927 parameter_idx = parameter_idx + 1;
1929 std::stringstream sstream;
1930 sstream << gate_idx <<
"th gate: RZ on target qubit: " << rz_gate->
get_target_qbit() <<
" and with parameters varphi = " << varphi << std::endl;
1932 gate_idx = gate_idx + 1;
1936 H* h_gate =
static_cast<H*
>(gate);
1937 std::stringstream sstream;
1938 sstream << gate_idx <<
"th gate: Hadamard on target qubit: " << h_gate->
get_target_qbit() << std::endl;
1940 gate_idx = gate_idx + 1;
1944 X* x_gate =
static_cast<X*
>(gate);
1945 std::stringstream sstream;
1946 sstream << gate_idx <<
"th gate: X on target qubit: " << x_gate->
get_target_qbit() << std::endl;
1948 gate_idx = gate_idx + 1;
1952 Y* y_gate =
static_cast<Y*
>(gate);
1953 std::stringstream sstream;
1954 sstream << gate_idx <<
"th gate: Y on target qubit: " << y_gate->
get_target_qbit() << std::endl;
1956 gate_idx = gate_idx + 1;
1960 Z* z_gate =
static_cast<Z*
>(gate);
1961 std::stringstream sstream;
1962 sstream << gate_idx <<
"th gate: Z on target qubit: " << z_gate->
get_target_qbit() << std::endl;
1964 gate_idx = gate_idx + 1;
1968 SX* sx_gate =
static_cast<SX*
>(gate);
1970 std::stringstream sstream;
1971 sstream << gate_idx <<
"th gate: SX on target qubit: " << sx_gate->
get_target_qbit() << std::endl;
1973 gate_idx = gate_idx + 1;
1978 block_gate->
list_gates( parameters_layer, gate_idx );
1985 std::stringstream sstream;
1986 sstream << gate_idx <<
"th gate: UN " << gate->
get_parameter_num() <<
" parameters" << std::endl;
1988 gate_idx = gate_idx + 1;
1994 CZ_NU* cz_nu_gate =
static_cast<CZ_NU*
>(gate);
1995 Theta = std::fmod( parameters_data[parameter_idx], 2*M_PI);
1996 parameter_idx = parameter_idx +1;
1998 std::stringstream sstream;
1999 sstream << gate_idx <<
"th gate: CZ_NU gate on target qubit: " << cz_nu_gate->
get_target_qbit() <<
", control qubit " << cz_nu_gate->
get_control_qbit() <<
" and with parameters Theta = " << Theta << std::endl;
2001 gate_idx = gate_idx + 1;
2005 std::stringstream sstream;
2006 sstream << gate_idx <<
"th gate: ON " << gate->
get_parameter_num() <<
" parameters" << std::endl;
2008 gate_idx = gate_idx + 1;
2013 std::stringstream sstream;
2014 sstream << gate_idx <<
"th gate: Composite " << gate->
get_parameter_num() <<
" parameters" << std::endl;
2016 gate_idx = gate_idx + 1;
2023 Theta = std::fmod( 2*parameters_data[parameter_idx], 4*M_PI);
2024 parameter_idx = parameter_idx + 1;
2026 std::stringstream sstream;
2027 sstream << gate_idx <<
"th gate: Adaptive gate on target qubit: " << ad_gate->
get_target_qbit() <<
", control qubit " << ad_gate->
get_control_qbit() <<
" and with parameters Theta = " << Theta << std::endl;
2029 gate_idx = gate_idx + 1;
2032 std::string err(
"Gates_block::list_gates: unimplemented gate");
2066 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
2094 if (qbit_map.find( target_qbit ) != qbit_map.end()) {
2097 std::string err(
"Gates_block::create_remapped_circuit: Missing target qubit from the qbit map.");
2102 if ( control_qbit != -1 ) {
2103 if ( qbit_map.find( control_qbit ) != qbit_map.end() ) {
2106 std::string err(
"Gates_block::create_remapped_circuit: Missing control qubit from the qbit map.");
2121 std::string err(
"Gates_block::create_remapped_circuit: unimplemented gate");
2137 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
2142 CNOT* cnot_gate =
static_cast<CNOT*
>(gate);
2146 CZ* cz_gate =
static_cast<CZ*
>(gate);
2150 CH* ch_gate =
static_cast<CH*
>(gate);
2154 SYC* syc_gate =
static_cast<SYC*
>(gate);
2158 U1* u1_gate =
static_cast<U1*
>(gate);
2162 U2* u2_gate =
static_cast<U2*
>(gate);
2166 U3* u3_gate =
static_cast<U3*
>(gate);
2170 R* r_gate =
static_cast<R*
>(gate);
2174 RX* rx_gate =
static_cast<RX*
>(gate);
2178 RY* ry_gate =
static_cast<RY*
>(gate);
2182 CRY* cry_gate =
static_cast<CRY*
>(gate);
2186 CR* cr_gate =
static_cast<CR*
>(gate);
2190 CROT* crot_gate =
static_cast<CROT*
>(gate);
2194 RZ* rz_gate =
static_cast<RZ*
>(gate);
2198 H* h_gate =
static_cast<H*
>(gate);
2202 X* x_gate =
static_cast<X*
>(gate);
2206 Y* y_gate =
static_cast<Y*
>(gate);
2210 Z* z_gate =
static_cast<Z*
>(gate);
2214 T* t_gate =
static_cast<T*
>(gate);
2218 Tdg* tdg_gate =
static_cast<Tdg*
>(gate);
2222 SX* sx_gate =
static_cast<SX*
>(gate);
2230 UN* un_gate =
static_cast<UN*
>(gate);
2234 ON* on_gate =
static_cast<ON*
>(gate);
2246 std::string err(
"Gates_block::reorder_qubits: unimplemented gate");
2266 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
2302 if (idx > (
int)
gates.size() ) {
2317 std::vector<Gate*> gates_in = op_block->
get_gates();
2321 std::string err(
"Gates_block::combine: number of qubits in the circuits must be the same");
2325 for(std::vector<Gate*>::iterator it = (gates_in).begin(); it != (gates_in).end(); ++it) {
2340 if (qbit_num_in > 30) {
2341 std::string err(
"Gates_block::set_qbit_num: Number of qubits supported up to 30");
2349 for(std::vector<Gate*>::iterator it =
gates.begin(); it !=
gates.end(); ++it) {
2368 std::string err(
"Gates_block::set_qbit_num: unimplemented gate");
2390 std::string err(
"Gates_block::clone(): extracting gates was not succesfull");
2408 for ( std::vector<Gate*>::iterator it=
gates.begin(); it !=
gates.end(); ++it ) {
2429 std::string err(
"Gates_block::extract_gates: unimplemented gate");
2447 for ( std::vector<Gate*>::iterator it=
gates.begin(); it !=
gates.end(); ++it ) {
2456 if ( ret )
return true;
2502 if (input_state.
cols != 1) {
2503 std::string error(
"Gates_block::get_reduced_density_matrix: The number of columns in input state should be 1");
2509 std::string error(
"Gates_block::get_reduced_density_matrix: The number of rows in input state should be 2^qbit_num");
2515 if ( parameters_mtx.
size() > 0 ) {
2516 bool parallel =
true;
2517 apply_to( parameters_mtx, transformed_state, parallel );
2521 int subset_qbit_num = qbit_list_subset.
size();
2522 int complementary_qbit_num =
qbit_num - subset_qbit_num;
2527 int qbit_idx_count = 0;
2528 for (
int qbit_idx=0; qbit_idx<
qbit_num; qbit_idx++) {
2530 bool qbit_idx_in_subset =
false;
2532 for (
int subset_qbit_idx=0; subset_qbit_idx<subset_qbit_num; subset_qbit_idx++) {
2533 if ( qbit_idx == qbit_list_subset[subset_qbit_idx] ) {
2534 qbit_idx_in_subset =
true;
2540 if ( qbit_idx_in_subset ) {
2544 qbit_list_complementary[qbit_idx_count] = qbit_idx;
2551 for (
int qbit_idx=0; qbit_idx<
qbit_num; qbit_idx++) {
2552 qbit_masks[ qbit_idx ] = 1 << qbit_idx;
2558 int rho_matrix_size = 1 << subset_qbit_num;
2560 Matrix rho(rho_matrix_size, rho_matrix_size);
2566 int complementary_basis_num = 1 << complementary_qbit_num;
2567 for (
int row_idx=0; row_idx<rho_matrix_size; row_idx++ ) {
2571 for (
int qbit_idx=0; qbit_idx<subset_qbit_num; qbit_idx++) {
2572 if ( row_idx & qbit_masks[ qbit_idx ] ) {
2573 idx = idx | qbit_masks[ qbit_list_subset[qbit_idx] ];
2577 for (
int col_idx=row_idx; col_idx<rho_matrix_size; col_idx++ ) {
2581 for (
int qbit_idx=0; qbit_idx<subset_qbit_num; qbit_idx++) {
2582 if ( col_idx & qbit_masks[ qbit_idx ] ) {
2583 jdx = jdx | qbit_masks[ qbit_list_subset[qbit_idx] ];
2589 tbb::combinable<QGD_Complex16> priv_addend {[](){
QGD_Complex16 ret; ret.
real = 0.0; ret.
imag = 0.0;
return ret;}};
2592 tbb::parallel_for( tbb::blocked_range<int>(0, complementary_basis_num, 1024), [&](tbb::blocked_range<int> r) {
2596 for (
int compl_idx=r.begin(); compl_idx<r.end(); compl_idx++) {
2602 for (
int qbit_idx=0; qbit_idx<complementary_qbit_num; qbit_idx++) {
2603 if ( compl_idx & qbit_masks[ qbit_idx ] ) {
2604 idx_loc = idx_loc | qbit_masks[ qbit_list_complementary[qbit_idx] ];
2605 jdx_loc = jdx_loc | qbit_masks[ qbit_list_complementary[qbit_idx] ];
2613 element_idx.
imag = -element_idx.
imag;
2617 rho_element_priv.
real = rho_element_priv.
real + addend.
real;
2618 rho_element_priv.
imag = rho_element_priv.
imag + addend.
imag;
2627 rho_element.
real = 0.0;
2628 rho_element.imag = 0.0;
2631 rho_element.real = rho_element.real + a.
real;
2632 rho_element.imag = rho_element.imag + a.
imag;
2635 rho[ row_idx * rho.
stride + col_idx ].real += rho_element.real;
2636 rho[ row_idx * rho.
stride + col_idx ].imag += rho_element.imag;
2638 if ( row_idx == col_idx ) {
2642 rho[ col_idx * rho.
stride + row_idx ].real += rho_element.real;
2643 rho[ col_idx * rho.
stride + row_idx ].imag -= rho_element.imag;
2653 for(
int idx=0; idx<rho_matrix_size; idx++) {
2654 trace = trace + rho[idx*rho.
stride+idx].real;
2657 if ( abs( trace-1.0 ) > 1e-6 ) {
2658 std::stringstream sstream;
2659 sstream <<
"Warning: Gates_block::get_reduced_density_matrix: The error of the trace of the reduced density matrix is " << abs( trace-1.0 ) << std::endl;
2684 double trace_rho_square = 0.0;
2686 for (
int idx=0; idx<rho.
rows; idx++) {
2688 double trace_tmp = 0.0;
2690 for (
int jdx=0; jdx<rho.
rows; jdx++) {
2694 trace_tmp = trace_tmp + tmp;
2698 trace_rho_square = trace_rho_square + trace_tmp;
2706 double entropy = -log(trace_rho_square);
2722 std::vector<int> ret = list1;
2724 for( std::vector<int>::iterator it2 = list2.begin(); it2 != list2.end(); it2++ ) {
2726 std::vector<int>::iterator element_found = std::find(ret.begin(), ret.end(), *it2);
2728 if( element_found != ret.end() ) {
2729 ret.erase( element_found );
2758 for(
int idx=
gates.size()-1; idx>=0; idx-- ) {
2764 if( reduced_qbit_list.size() < involved_qubits.size() ) {
2770 involved_qubits = std::move(reduced_qbit_list);
2777 if( involved_qubits.size() == 0 ) {
2798 for(
int idx=0; idx<
gates.size(); idx++ ) {
2804 if( reduced_qbit_list.size() < involved_qubits.size() ) {
2810 involved_qubits = std::move(reduced_qbit_list);
2817 if( involved_qubits.size() == 0 ) {
2833 for( std::vector<Gate*>::iterator gate_it =
gates.begin(); gate_it !=
gates.end(); gate_it++ ) {
2835 Gate* gate = *gate_it;
2853 for( std::vector<Gate*>::iterator gate_it =
gates.begin(); gate_it !=
gates.end(); gate_it++ ) {
2854 Gate* gate = *gate_it;
2861 for( std::vector<Gate*>::iterator gate_it =
gates.begin(); gate_it !=
gates.end(); gate_it++ ) {
2862 Gate* gate = *gate_it;
2883 for( std::vector<Gate*>::iterator gate_it=
gates.begin(); gate_it !=
gates.end(); gate_it++ ) {
2885 Gate* gate = *gate_it;
2892 flat_circuit->
combine( flat_circuit_inner );
2894 delete( flat_circuit_inner );
2904 return flat_circuit;
2920 std::string err(
"Gates_block::extract_parameters: Cant extract parameters, since th einput arary has not enough elements.");
2928 return extracted_parameters;
2940 DFEgate_kernel_type* Gates_block::convert_to_DFE_gates_with_derivates(
Matrix_real& parameters_mtx,
int& gatesNum,
int& gateSetNum,
int& redundantGateSets,
bool only_derivates ) {
2943 if ( parameter_num != parameters_mtx.
size() ) {
2944 std::string error(
"Gates_block::convert_to_DFE_gates: wrong number of parameters");
2949 int gates_total_num = 0;
2950 for(
auto it=gate_nums.begin(); it != gate_nums.end(); it++ ) {
2951 gates_total_num = gates_total_num + it->second;
2955 int gate_padding = gates_total_num % chained_gates_num == 0 ? 0 : chained_gates_num - (gates_total_num % chained_gates_num);
2956 gatesNum = gates_total_num+gate_padding;
2963 gateSetNum = only_derivates ?
parameter_num : parameter_num+1;
2968 redundantGateSets = 0;
2972 gateSetNum = gateSetNum + redundantGateSets;
2975 int rem = gateSetNum % 4;
2977 redundantGateSets = 0;
2980 redundantGateSets = 4 - (gateSetNum % 4);
2981 gateSetNum = gateSetNum + redundantGateSets;
2990 convert_to_DFE_gates( parameters_mtx, DFEgates, gate_idx );
2994 for (
int idx=gate_idx; idx<gatesNum; idx++ ){
3003 DFEGate.
Phi = (int32_t)(0);
3004 DFEGate.
Lambda = (int32_t)(0);
3016 if (only_derivates ) {
3017 for (
int idx=1; idx<(gateSetNum-1); idx++) {
3022 for (
int idx=0; idx<(gateSetNum-1); idx++) {
3028 int gate_set_index = parameter_num-1;
3029 if (only_derivates) {
3030 adjust_parameters_for_derivation( DFEgates, gatesNum, gate_idx, gate_set_index );
3033 adjust_parameters_for_derivation( DFEgates+gatesNum, gatesNum, gate_idx, gate_set_index );
3051 void Gates_block::adjust_parameters_for_derivation(
DFEgate_kernel_type* DFEgates,
const int gatesNum,
int& gate_idx,
int& gate_set_index) {
3056 int32_t parameter_shift = (int32_t)(M_PI/2*(1<<25));
3058 for(
int op_idx =
gates.size()-1; op_idx>=0; op_idx--) {
3064 gate_idx = gate_idx + 1;
3067 gate_idx = gate_idx + 1;
3070 gate_idx = gate_idx + 1;
3073 std::string error(
"Gates_block::convert_to_DFE_gates: SYC_gate not implemented");
3081 gate_set_index = gate_set_index - 1;
3083 parameter_idx = parameter_idx - 1;
3084 gate_idx = gate_idx + 1;
3091 gate_set_index = gate_set_index - 1;
3095 DFEGate.
Phi = DFEGate.
Phi + parameter_shift;
3097 gate_set_index = gate_set_index - 1;
3099 parameter_idx = parameter_idx - 2;
3100 gate_idx = gate_idx + 1;
3107 gate_set_index = gate_set_index - 1;
3111 DFEGate2.
Phi = DFEGate2.
Phi + parameter_shift;
3113 gate_set_index = gate_set_index - 1;
3119 gate_set_index = gate_set_index - 1;
3121 parameter_idx = parameter_idx - 3;
3122 gate_idx = gate_idx + 1;
3129 gate_set_index = gate_set_index - 1;
3131 parameter_idx = parameter_idx - 1;
3133 gate_idx = gate_idx + 1;
3140 gate_set_index = gate_set_index - 1;
3142 parameter_idx = parameter_idx - 1;
3145 gate_idx = gate_idx + 1;
3152 gate_set_index = gate_set_index - 1;
3154 parameter_idx = parameter_idx - 1;
3156 gate_idx = gate_idx + 1;
3160 std::string error(
"Gates_block::adjust_parameters_for_derivation: RZ gate not implemented for DFE");
3166 DFEGate.
Phi = DFEGate.
Phi + parameter_shift;
3168 gate_set_index = gate_set_index - 1;
3170 parameter_idx = parameter_idx - 1;
3172 gate_idx = gate_idx + 1;
3175 std::string error(
"Gates_block::convert_to_DFE_gates: H_gate not implemented");
3180 std::string error(
"Gates_block::convert_to_DFE_gates: X_gate not implemented");
3185 std::string error(
"Gates_block::convert_to_DFE_gates: Y_gate not implemented");
3190 std::string error(
"Gates_block::convert_to_DFE_gates: Z_gate not implemented");
3195 std::string error(
"Gates_block::convert_to_DFE_gates: T_gate not implemented");
3200 std::string error(
"Gates_block::convert_to_DFE_gates: Tdg_gate not implemented");
3204 std::string error(
"Gates_block::convert_to_DFE_gates: SX_gate not implemented");
3210 block_gate->adjust_parameters_for_derivation( DFEgates, gatesNum, gate_idx, gate_set_index);
3216 std::string error(
"Gates_block::convert_to_DFE_gates: UN_gate not implemented");
3222 std::string error(
"Gates_block::convert_to_DFE_gates: ON_gate not implemented");
3226 std::string error(
"Gates_block::convert_to_DFE_gates: Composite_gate not implemented");
3230 std::string error(
"Gates_block::convert_to_DFE_gates: general_gate not implemented");
3238 gate_set_index = gate_set_index - 1;
3240 parameter_idx = parameter_idx - 1;
3242 gate_idx = gate_idx + 1;
3245 std::string err(
"Gates_block::adjust_parameters_for_derivation: unimplemented gate");
3260 Gates_block::convert_to_batched_DFE_gates( std::vector<Matrix_real>& parameters_mtx_vec,
int& gatesNum,
int& gateSetNum,
int& redundantGateSets ) {
3264 int gates_total_num = 0;
3265 for(
auto it=gate_nums.begin(); it != gate_nums.end(); it++ ) {
3266 gates_total_num = gates_total_num + it->second;
3270 int gate_padding = gates_total_num % chained_gates_num == 0 ? 0 : chained_gates_num - (gates_total_num % chained_gates_num);
3271 gatesNum = gates_total_num+gate_padding;
3278 gateSetNum = parameters_mtx_vec.size();
3283 redundantGateSets = 0;
3287 gateSetNum = gateSetNum + redundantGateSets;
3290 int rem = gateSetNum % 4;
3292 redundantGateSets = 0;
3295 redundantGateSets = 4 - (gateSetNum % 4);
3296 gateSetNum = gateSetNum + redundantGateSets;
3303 tbb::parallel_for( 0, gateSetNum, 1, [&](
int gateset_idx) {
3305 int gate_idx = gateset_idx * gatesNum;
3307 if ( gateset_idx < parameters_mtx_vec.size() ) {
3308 Matrix_real& parameters_mtx = parameters_mtx_vec[gateset_idx];
3309 convert_to_DFE_gates( parameters_mtx, DFEgates, gate_idx );
3313 for (
int idx=gate_idx; idx<(gateset_idx+1)*gatesNum; idx++ ){
3322 DFEGate.
Phi = (int32_t)(0);
3323 DFEGate.
Lambda = (int32_t)(0);
3344 if ( parameter_num != parameters_mtx.
size() ) {
3345 std::string error(
"Gates_block::convert_to_DFE_gates: wrong number of parameters");
3351 int gates_total_num = 0;
3352 for(
auto it=gate_nums.begin(); it != gate_nums.end(); it++ ) {
3353 gates_total_num = gates_total_num + it->second;
3357 int gate_padding = chained_gates_num - (gates_total_num % chained_gates_num);
3358 gatesNum = gates_total_num+gate_padding;
3365 convert_to_DFE_gates( parameters_mtx, DFEgates, gate_idx );
3369 for (
int idx=gate_idx; idx<gatesNum; idx++ ){
3378 DFEGate.
Phi = (int32_t)(0);
3379 DFEGate.
Lambda = (int32_t)(0);
3404 int& gate_idx = start_index;
3406 double *parameters_data = parameters_mtx.
get_data();
3410 for(
int op_idx =
gates.size()-1; op_idx>=0; op_idx--) {
3416 CNOT* cnot_gate =
static_cast<CNOT*
>(gate);
3420 DFEGate.
ThetaOver2 = (int32_t)(M_PI/2*(1<<25));
3421 DFEGate.
Phi = (int32_t)(0);
3422 DFEGate.
Lambda = (int32_t)(M_PI*(1<<25));
3424 gate_idx = gate_idx + 1;
3427 CZ* cz_gate =
static_cast<CZ*
>(gate);
3432 DFEGate.
Phi = (int32_t)(0);
3433 DFEGate.
Lambda = (int32_t)(M_PI*(1<<25));
3435 gate_idx = gate_idx + 1;
3438 CH* ch_gate =
static_cast<CH*
>(gate);
3442 DFEGate.
ThetaOver2 = (int32_t)(M_PI/4*(1<<25));
3443 DFEGate.
Phi = (int32_t)(0);
3444 DFEGate.
Lambda = (int32_t)(M_PI*(1<<25));
3446 gate_idx = gate_idx + 1;
3449 std::string error(
"Gates_block::convert_to_DFE_gates: SYC_gate not implemented");
3453 double lambda = std::fmod(parameters_data[parameter_idx-1], 2*M_PI);
3454 parameter_idx = parameter_idx - 1;
3460 DFEGate.
Phi = (int32_t)(0);
3461 DFEGate.
Lambda = (int32_t)(lambda*(1<<25));
3463 gate_idx = gate_idx + 1;
3466 double phi = std::fmod(parameters_data[parameter_idx-2], 2*M_PI);
3467 double lambda = std::fmod(parameters_data[parameter_idx-1], 2*M_PI);
3468 parameter_idx = parameter_idx - 2;
3473 DFEGate.
ThetaOver2 = (int32_t)(M_PI/4*(1<<25));
3474 DFEGate.
Phi = (int32_t)(phi*(1<<25));
3475 DFEGate.
Lambda = (int32_t)(lambda*(1<<25));
3477 gate_idx = gate_idx + 1;
3480 double theta = std::fmod(parameters_data[parameter_idx-3], 4*M_PI);
3481 double phi = std::fmod(parameters_data[parameter_idx-2], 2*M_PI);
3482 double lambda = std::fmod(parameters_data[parameter_idx-1], 2*M_PI);
3483 parameter_idx = parameter_idx - 3;
3488 DFEGate.
ThetaOver2 = (int32_t)(theta/2.0*(1<<25));
3489 DFEGate.
Phi = (int32_t)(phi*(1<<25));
3490 DFEGate.
Lambda = (int32_t)(lambda*(1<<25));
3492 gate_idx = gate_idx + 1;
3496 double varthetaOver2;
3498 RX* rx_gate =
static_cast<RX*
>(gate);
3499 varthetaOver2 = std::fmod( parameters_data[parameter_idx-1], 2*M_PI);
3500 parameter_idx = parameter_idx - 1;
3505 DFEGate.
ThetaOver2 = (int32_t)(varthetaOver2*(1<<25));
3506 DFEGate.
Phi = (int32_t)(-M_PI/2*(1<<25));
3507 DFEGate.
Lambda = (int32_t)(M_PI/2*(1<<25));
3510 gate_idx = gate_idx + 1;
3514 double varthetaOver2;
3516 RY* ry_gate =
static_cast<RY*
>(gate);
3517 varthetaOver2 = std::fmod( parameters_data[parameter_idx-1], 2*M_PI);
3518 parameter_idx = parameter_idx - 1;
3523 DFEGate.
ThetaOver2 = (int32_t)(varthetaOver2*(1<<25));
3524 DFEGate.
Phi = (int32_t)(0);
3525 DFEGate.
Lambda = (int32_t)(0);
3528 gate_idx = gate_idx + 1;
3534 CRY* cry_gate =
static_cast<CRY*
>(gate);
3535 double varthetaOver2 = std::fmod( parameters_data[parameter_idx-1], 2*M_PI);
3536 parameter_idx = parameter_idx - 1;
3540 DFEGate.
ThetaOver2 = (int32_t)(varthetaOver2*(1<<25));
3541 DFEGate.
Phi = (int32_t)(0);
3542 DFEGate.
Lambda = (int32_t)(0);
3545 gate_idx = gate_idx + 1;
3549 std::string error(
"Gates_block::convert_to_DFE_gates: RZ gate not implemented for DFE. Use RZ_P gate instead that differs from RZ gate by a global phase");
3558 RZ* rz_gate =
static_cast<RZ*
>(gate);
3559 varphi = std::fmod( parameters_data[parameter_idx-1], 2*M_PI);
3560 parameter_idx = parameter_idx - 1;
3566 DFEGate.
Phi = (int32_t)(varphi*(1<<25));
3567 DFEGate.
Lambda = (int32_t)(0);
3570 gate_idx = gate_idx + 1;
3574 H* h_gate =
static_cast<H*
>(gate);
3576 std::string error(
"Gates_block::convert_to_DFE_gates: Hadamard gate not implemented");
3579 gate_idx = gate_idx + 1;
3583 X* x_gate =
static_cast<X*
>(gate);
3588 DFEGate.
ThetaOver2 = (int32_t)(M_PI/2*(1<<25));
3589 DFEGate.
Phi = (int32_t)(0);
3590 DFEGate.
Lambda = (int32_t)(M_PI*(1<<25));
3593 gate_idx = gate_idx + 1;
3597 Y* y_gate =
static_cast<Y*
>(gate);
3602 DFEGate.
ThetaOver2 = (int32_t)(M_PI/2*(1<<25));
3603 DFEGate.
Phi = (int32_t)(M_PI/2*(1<<25));
3604 DFEGate.
Lambda = (int32_t)(M_PI/2*(1<<25));
3607 gate_idx = gate_idx + 1;
3611 Z* z_gate =
static_cast<Z*
>(gate);
3617 DFEGate.
Phi = (int32_t)(0);
3618 DFEGate.
Lambda = (int32_t)(M_PI*(1<<25));
3621 gate_idx = gate_idx + 1;
3625 SX* sx_gate =
static_cast<SX*
>(gate);
3626 std::string error(
"Gates_block::convert_to_DFE_gates: SX_gate not implemented");
3632 block_gate->convert_to_DFE_gates( parameters_layer_mtx, DFEgates, gate_idx );
3636 std::string error(
"Gates_block::convert_to_DFE_gates: UN_gate not implemented");
3642 std::string error(
"Gates_block::convert_to_DFE_gates: ON_gate not implemented");
3646 std::string error(
"Gates_block::convert_to_DFE_gates: Composite_gate not implemented");
3650 std::string error(
"Gates_block::convert_to_DFE_gates: general_gate not implemented");
3659 parameter_idx = parameter_idx - 1;
3663 DFEGate.
ThetaOver2 = (int32_t)(varthetaOver2*(1<<25));
3664 DFEGate.
Phi = (int32_t)(0);
3665 DFEGate.
Lambda = (int32_t)(0);
3668 gate_idx = gate_idx + 1;
3671 std::string err(
"Gates_block::convert_to_DFE_gates: unimplemented gate");
3690 Gates_block::extract_gate_kernels_target_and_control_qubits(std::vector<Matrix> &u3_qbit, std::vector<int> &
target_qbit, std::vector<int> &
control_qbit,
Matrix_real& parameters_mtx)
3693 if ( u3_qbit.size() == 0 ) {
3695 int gates_total_num = 0;
3696 for(
auto it=gate_nums.begin(); it != gate_nums.end(); it++ ) {
3697 gates_total_num = gates_total_num + it->second;
3700 u3_qbit.reserve( gates_total_num );
3712 for(
int idx=0; idx<
gates.size(); idx++) {
3721 CNOT* cnot_operation =
static_cast<CNOT*
>(operation);
3726 H* h_operation =
static_cast<H*
>(operation);
3731 X* x_operation =
static_cast<X*
>(operation);
3736 Y* y_operation =
static_cast<Y*
>(operation);
3741 Z* z_operation =
static_cast<Z*
>(operation);
3746 T* t_operation =
static_cast<T*
>(operation);
3751 Tdg* tdg_operation =
static_cast<Tdg*
>(operation);
3756 SX* sx_operation =
static_cast<SX*
>(operation);
3761 U1* u1_operation =
static_cast<U1*
>(operation);
3766 U2* u2_operation =
static_cast<U2*
>(operation);
3767 u3_qbit.push_back(u2_operation->
calc_one_qubit_u3(params_mtx[0], params_mtx[1]));
3771 U3* u3_operation =
static_cast<U3*
>(operation);
3772 u3_qbit.push_back(u3_operation->
calc_one_qubit_u3(params_mtx[0], params_mtx[1], params_mtx[2]));
3776 RX* rx_operation =
static_cast<RX*
>(operation);
3778 double ThetaOver2 = params_mtx[0];
3779 double Phi = -M_PI/2;
3786 RY* ry_operation =
static_cast<RY*
>(operation);
3787 double ThetaOver2 = params_mtx[0];
3795 CRY* cry_operation =
static_cast<CRY*
>(operation);
3797 ThetaOver2 = params_mtx[0];
3803 RZ* rz_operation =
static_cast<RZ*
>(operation);
3824 if ( involved_qubits.size() == 1 && block_operation->
gates.size() > 1 && block_operation->
get_qbit_num() > 1 ) {
3829 for (
int idx=0; idx<block_operation->
gates.size(); idx++){
3830 Gate* gate = block_operation->
gates[idx]->clone();
3839 gates_block_mini.
apply_to(params_mtx, merged_kernel);
3841 u3_qbit.push_back( merged_kernel );
3847 block_operation->extract_gate_kernels_target_and_control_qubits(u3_qbit,
target_qbit,
control_qbit, params_mtx);
3858 std::string err(
"Optimization_Interface::apply_to: unimplemented gate (" + std::to_string(operation->
get_type()) +
")");
3880 std::stringstream sstream;
3881 sstream <<
"Exporting circuit into binary format. Filename: " << filename << std::endl;
3884 log.
print(sstream, 3);
3887 const char* c_filename = filename.c_str();
3889 pFile = fopen(c_filename,
"wb");
3890 if (pFile==NULL) {fputs (
"File error",stderr); exit (1);}
3909 fwrite(&qbit_num,
sizeof(
int), 1, pFile);
3912 fwrite(¶meter_num,
sizeof(
int), 1, pFile);
3916 fwrite(&gates_num,
sizeof(
int), 1, pFile);
3921 double* parameters_data = parameters.
get_data();
3923 for ( std::vector<Gate*>::iterator it=gates.begin(); it != gates.end(); ++it ) {
3928 fwrite(>_type,
sizeof(
gate_type), 1, pFile);
3935 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3936 fwrite(&control_qbit,
sizeof(
int), 1, pFile);
3940 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3941 fwrite(parameters_data,
sizeof(
double), parameter_num, pFile);
3945 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3947 fwrite(parameters_data,
sizeof(
double), parameter_num, pFile);
3952 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3953 fwrite(&control_qbit,
sizeof(
int), 1, pFile);
3955 fwrite(parameters_data,
sizeof(
double), parameter_num, pFile);
3960 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3964 Matrix_real parameters_loc(parameters_data, 1, parameter_num);
3971 fwrite(&target_qbit,
sizeof(
int), 1, pFile);
3972 fwrite(&control_qbit,
sizeof(
int), 1, pFile);
3974 fwrite(parameters_data,
sizeof(
double), parameter_num, pFile);
3977 std::string err(
"export_gate_list_to_binary: unimplemented gate");
3995 std::stringstream sstream;
3996 sstream <<
"Importing quantum circuit from binary file " << filename << std::endl;
3999 log.
print(sstream, 2);
4002 const char* c_filename = filename.c_str();
4004 pFile = fopen(c_filename,
"rb");
4005 if (pFile==NULL) {fputs (
"File error",stderr); exit (1);}
4019 std::stringstream sstream;
4022 size_t fread_status;
4024 fread_status = fread(&qbit_num,
sizeof(
int), 1, pFile);
4025 sstream <<
"qbit_num: " << qbit_num << std::endl;
4029 fread_status = fread(¶meter_num,
sizeof(
int), 1, pFile);
4030 sstream <<
"parameter_num: " << parameter_num << std::endl;
4032 double* parameters_data = parameters.
get_data();
4035 fread_status = fread(&gates_num,
sizeof(
int), 1, pFile);
4036 sstream <<
"gates_num: " << gates_num << std::endl;
4038 std::vector<int> gate_block_level_gates_num;
4039 std::vector<Gates_block*> gate_block_levels;
4040 gate_block_level_gates_num.push_back( gates_num );
4041 gate_block_levels.push_back(gate_block);
4042 int current_level = 0;
4048 while ( gate_block_level_gates_num[0] > 0 && iter < iter_max) {
4051 fread_status = fread(>_type,
sizeof(
gate_type), 1, pFile);
4056 sstream <<
"importing CNOT gate" << std::endl;
4059 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4060 sstream <<
"target_qbit: " << target_qbit << std::endl;
4063 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4064 sstream <<
"control_qbit: " << control_qbit << std::endl;
4066 gate_block_levels[current_level]->add_cnot(target_qbit, control_qbit);
4067 gate_block_level_gates_num[current_level]--;
4070 sstream <<
"importing CZ gate" << std::endl;
4073 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4074 sstream <<
"target_qbit: " << target_qbit << std::endl;
4077 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4078 sstream <<
"control_qbit: " << control_qbit << std::endl;
4080 gate_block_levels[current_level]->add_cz(target_qbit, control_qbit);
4081 gate_block_level_gates_num[current_level]--;
4084 sstream <<
"importing CH gate" << std::endl;
4087 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4088 sstream <<
"target_qbit: " << target_qbit << std::endl;
4091 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4092 sstream <<
"control_qbit: " << control_qbit << std::endl;
4094 gate_block_levels[current_level]->add_ch(target_qbit, control_qbit);
4095 gate_block_level_gates_num[current_level]--;
4098 sstream <<
"importing SYCAMORE gate" << std::endl;
4101 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4102 sstream <<
"target_qbit: " << target_qbit << std::endl;
4105 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4106 sstream <<
"control_qbit: " << control_qbit << std::endl;
4108 gate_block_levels[current_level]->add_syc(target_qbit, control_qbit);
4109 gate_block_level_gates_num[current_level]--;
4112 sstream <<
"importing U1 gate" << std::endl;
4115 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4116 sstream <<
"target_qbit: " << target_qbit << std::endl;
4118 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4121 gate_block_levels[current_level]->add_u1(target_qbit);
4122 gate_block_level_gates_num[current_level]--;
4125 sstream <<
"importing U2 gate" << std::endl;
4128 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4129 sstream <<
"target_qbit: " << target_qbit << std::endl;
4131 fread_status = fread(parameters_data,
sizeof(
double), 2, pFile);
4134 gate_block_levels[current_level]->add_u2(target_qbit);
4135 gate_block_level_gates_num[current_level]--;
4138 sstream <<
"importing U3 gate" << std::endl;
4141 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4142 sstream <<
"target_qbit: " << target_qbit << std::endl;
4144 fread_status = fread(parameters_data,
sizeof(
double), 3, pFile);
4146 parameters_data += 3;
4147 gate_block_levels[current_level]->add_u3(target_qbit);
4148 gate_block_level_gates_num[current_level]--;
4152 sstream <<
"importing RX gate" << std::endl;
4155 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4156 sstream <<
"target_qbit: " << target_qbit << std::endl;
4158 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4161 gate_block_levels[current_level]->add_rx(target_qbit);
4162 gate_block_level_gates_num[current_level]--;
4167 sstream <<
"importing RY gate" << std::endl;
4170 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4171 sstream <<
"target_qbit: " << target_qbit << std::endl;
4173 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4176 gate_block_levels[current_level]->add_ry(target_qbit);
4177 gate_block_level_gates_num[current_level]--;
4182 sstream <<
"importing CRY gate" << std::endl;
4185 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4186 sstream <<
"target_qbit: " << target_qbit << std::endl;
4189 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4190 sstream <<
"control_qbit: " << control_qbit << std::endl;
4192 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4195 gate_block_levels[current_level]->add_cry(target_qbit, control_qbit);
4196 gate_block_level_gates_num[current_level]--;
4201 sstream <<
"importing RZ gate" << std::endl;
4204 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4205 sstream <<
"target_qbit: " << target_qbit << std::endl;
4207 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4210 gate_block_levels[current_level]->add_rz(target_qbit);
4211 gate_block_level_gates_num[current_level]--;
4216 sstream <<
"importing Hadamard gate" << std::endl;
4219 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4220 sstream <<
"target_qbit: " << target_qbit << std::endl;
4222 gate_block_levels[current_level]->add_h(target_qbit);
4223 gate_block_level_gates_num[current_level]--;
4228 sstream <<
"importing X gate" << std::endl;
4231 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4232 sstream <<
"target_qbit: " << target_qbit << std::endl;
4234 gate_block_levels[current_level]->add_x(target_qbit);
4235 gate_block_level_gates_num[current_level]--;
4240 sstream <<
"importing Y gate" << std::endl;
4243 fread(&target_qbit,
sizeof(
int), 1, pFile);
4244 sstream <<
"target_qbit: " << target_qbit << std::endl;
4246 gate_block_levels[current_level]->add_y(target_qbit);
4247 gate_block_level_gates_num[current_level]--;
4252 sstream <<
"importing Z gate" << std::endl;
4255 fread(&target_qbit,
sizeof(
int), 1, pFile);
4256 sstream <<
"target_qbit: " << target_qbit << std::endl;
4258 gate_block_levels[current_level]->add_z(target_qbit);
4259 gate_block_level_gates_num[current_level]--;
4264 sstream <<
"importing T gate" << std::endl;
4267 fread(&target_qbit,
sizeof(
int), 1, pFile);
4268 sstream <<
"target_qbit: " << target_qbit << std::endl;
4270 gate_block_levels[current_level]->add_t(target_qbit);
4271 gate_block_level_gates_num[current_level]--;
4276 sstream <<
"importing Tdg gate" << std::endl;
4279 fread(&target_qbit,
sizeof(
int), 1, pFile);
4280 sstream <<
"target_qbit: " << target_qbit << std::endl;
4282 gate_block_levels[current_level]->add_t(target_qbit);
4283 gate_block_level_gates_num[current_level]--;
4288 sstream <<
"importing SX gate" << std::endl;
4291 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4292 sstream <<
"target_qbit: " << target_qbit << std::endl;
4294 gate_block_levels[current_level]->add_sx(target_qbit);
4295 gate_block_level_gates_num[current_level]--;
4301 sstream <<
"******* importing gates block ********" << std::endl;
4304 fread_status = fread(&qbit_num_loc,
sizeof(
int), 1, pFile);
4308 int parameter_num_loc;
4309 fread_status = fread(¶meter_num_loc,
sizeof(
int), 1, pFile);
4314 fread_status = fread(&gates_num_loc,
sizeof(
int), 1, pFile);
4317 gate_block_levels.push_back( gate_block_inner );
4318 gate_block_level_gates_num.push_back(gates_num_loc);
4323 sstream <<
"importing adaptive gate" << std::endl;
4326 fread_status = fread(&target_qbit,
sizeof(
int), 1, pFile);
4327 sstream <<
"target_qbit: " << target_qbit << std::endl;
4330 fread_status = fread(&control_qbit,
sizeof(
int), 1, pFile);
4331 sstream <<
"control_qbit: " << control_qbit << std::endl;
4333 fread_status = fread(parameters_data,
sizeof(
double), 1, pFile);
4336 gate_block_levels[current_level]->add_adaptive(target_qbit, control_qbit);
4337 gate_block_level_gates_num[current_level]--;
4341 std::string err(
"import_gate_list_from_binary: unimplemented gate");
4346 if ( gate_block_level_gates_num[current_level] == 0 ) {
4347 gate_block_levels[ current_level-1 ]->add_gate( static_cast<Gate*>(gate_block_levels[ current_level ]) );
4348 gate_block_levels.pop_back();
4349 gate_block_level_gates_num.pop_back();
4351 gate_block_level_gates_num[current_level]--;
4352 sstream <<
"finishing gates block" << std::endl;
4361 log.
print(sstream, 4);
4364 if ( iter == iter_max ) {
4365 std::string error(
"Corrupted input file, reached end of the file before contructing the whole gate structure");
4383 if ( parameters_in.
cols > 1 && parameters_in.
rows > 1 ) {
4384 std::string error(
"reverse_parameters: Input array should have a single column or a single row.");
4391 int parameters_num_total = 0;
4392 for (
int idx=0; idx<num_of_gates; idx++) {
4395 Gate* gate = *(gates_it++);
4401 if ( parameters_num_total == 0) {
4409 Matrix_real parameters_ret(1, parameters_num_total);
4410 int parameter_num_copied = 0;
4413 for (
int idx=num_of_gates-0; idx>0; idx--) {
4416 Gate* gate = *(--gates_it);
4420 if ( parameter_num_gate == 0 ) {
4429 Matrix_real parameters_of_block( parameters_in.
get_data()+parameters_num_total, 1, parameter_num_gate );
4434 std::vector<Gate*> gates_loc = block_gate->
get_gates();
4440 memcpy( parameters_ret.
get_data()+parameter_num_copied, parameters_of_block_reversed.
get_data(), parameters_of_block_reversed.
size()*
sizeof(double) );
4441 parameter_num_copied = parameter_num_copied + parameters_of_block_reversed.
size();
4463 return parameters_ret;
4481 if ( parameters_in.
cols > 1 && parameters_in.
rows > 1 ) {
4482 std::string error(
"reverse_parameters: Input array should have a single column or a single row.");
4488 int parameters_num_total = 0;
4489 for (
int idx=0; idx<num_of_gates; idx++) {
4492 Gate* gate = *(gates_it++);
4498 if ( parameters_num_total == 0) {
4506 Matrix_real parameters_ret(1, parameters_num_total);
4507 int parameter_num_copied = 0;
4510 for (
int idx=num_of_gates-0; idx>0; idx--) {
4513 Gate* gate = *(--gates_it);
4517 if ( parameter_num_gate == 0 ) {
4526 Matrix_real parameters_of_block( parameters_in.
get_data()+parameters_num_total, 1, parameter_num_gate );
4531 std::vector<Gate*> gates_loc = block_gate->
get_gates();
4537 memcpy( parameters_ret.
get_data()+parameter_num_copied, parameters_of_block_reversed.
get_data(), parameters_of_block_reversed.
size()*
sizeof(double) );
4538 parameter_num_copied = parameter_num_copied + parameters_of_block_reversed.
size();
4560 return parameters_ret;
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
bool isnan()
Call to check the array for NaN entries.
Header file for a class representing the T gate.
Gates_block * get_flat_circuit()
Method to generate a flat circuit.
A class representing a U3 gate.
void add_adaptive(int target_qbit, int control_qbit)
Append a Adaptive gate to the list of gates.
A class representing a U3 gate.
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
Header file for a class representing a single qubit gate with custom gate kernel. ...
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void add_composite_to_front()
Add a Composite gate to the front of the list of gates.
int get_chained_gates_num()
Call to retrieve the number of gates that should be chained up during the execution of the DFE librar...
Base class for the representation of general gate operations.
void parameters_for_calc_one_qubit(double &ThetaOver2, double &Phi, double &Lambda)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
void add_cz_nu(int target_qbit, int control_qbit)
Append a CZ_NU gate to the list of gates.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
void apply_to_list(Matrix_real ¶meters, std::vector< Matrix > &inputs, int parallel)
Call to apply the gate on the input array/matrix by U3*input.
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
Header file for a class representing a rotation gate around the X axis.
void release_gate(int idx)
Call to release one gate in the list.
void determine_parents(Gate *gate)
Call to obtain the parent gates in the circuit.
void add_z_to_front(int target_qbit)
Add a Z gate to the front of the list of gates.
Header file for a class for a composite gate operation.
void add_child(Gate *child)
Call to add a child gate to the current gate.
void add_h(int target_qbit)
Append a Hadamard gate to the list of gates.
A class representing a U2 gate.
virtual Matrix get_matrix()
Call to retrieve the operation matrix.
void clear_children()
Call to erase data on children.
A class representing a custom_kernel_1qubit_gate gate.
Header file for a class representing the X gate.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
std::map< std::string, int > get_gate_nums()
Call to get the number of the individual gate types in the list of gates.
Header file for a class representing the Y gate.
void add_x(int target_qbit)
Append a X gate to the list of gates.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
virtual std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters_mtx_in, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
void add_cz_nu_to_front(int target_qbit, int control_qbit)
Add a CZ_NU gate to the front of the list of gates.
virtual Gate * clone()
Call to create a clone of the present class.
void add_gate(Gate *gate)
Append a general gate to the list of gates.
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
Header file for a class representing a controlled rotation gate around the Y axis.
void add_u2(int target_qbit)
Append a U2 gate to the list of gates.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
Header file for a class representing the SX axis.
std::vector< int > get_involved_qubits()
Call to get the qubits involved in the gates stored in the block of gates.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void add_cnot_to_front(int target_qbit, int control_qbit)
Add a C_NOT gate gate to the front of the list of gates.
void parameters_for_calc_one_qubit(double &ThetaOver2, double &Phi, double &Lambda)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
int max_fusion
maximal number of qubits in partitions
void add_u1(int target_qbit)
Append a U1 gate to the list of gates.
void add_on_to_front()
Add a OUN gate to the front of the list of gates.
Header file for a class representing a controlled rotation gate around the Y axis.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*CZ.
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
Matrix_real reverse_parameters(const Matrix_real ¶meters_in, std::vector< Gate *>::iterator gates_it, int num_of_gates)
Call to reverse the order of the parameters in an array.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*Gate.
std::vector< Gate * > get_gates()
Call to get the gates stored in the class.
Gates_block * create_remapped_circuit(const std::map< int, int > &qbit_map)
Call to create a new circuit with remapped qubits.
void release_gates()
Call to release the stored gates.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gates (Obsolete function)
std::vector< int > block_type
Header file for a class representing a CH operation.
void get_parameter_max(Matrix_real &range_max)
data
load the unitary from file
void add_r(int target_qbit)
Append a R gate to the list of gates.
std::vector< std::vector< int > > involved_qbits
Header file for a class responsible for grouping gates into subcircuits. (Subcircuits can be nested) ...
A class representing a U3 gate.
Header file for a class representing the Tdg gate.
int layer_num
number of gate layers
void add_cnot(int target_qbit, int control_qbit)
Append a CNOT gate gate to the list of gates.
void add_cr(int target_qbit, int control_qbit)
Append a CR gate to the list of gates.
QGD_Complex16 mult(QGD_Complex16 &a, QGD_Complex16 &b)
Call to calculate the product of two complex scalars.
A class representing a U3 gate.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
bool fragmented
boolean variable indicating whether the circuit was already partitioned or not
void add_cz_to_front(int target_qbit, int control_qbit)
Add a CZ gate gate to the front of the list of gates.
virtual void apply_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel=0)
Call to apply the gate on the input array/matrix Gates_block*input.
int matrix_size
The size N of the NxN matrix associated with the operations.
scalar * get_data() const
Call to get the pointer to the stored data.
void add_rz_to_front(int target_qbit)
Add a RZ gate to the front of the list of gates.
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*CRY.
void add_r_to_front(int target_qbit)
Add a R gate to the front of the list of gates.
void add_un_to_front()
Add a UN gate to the front of the list of gates.
Gates_block * import_gate_list_from_binary(Matrix_real ¶meters, const std::string &filename, int verbosity)
?????????
int get_gate_num()
Call to get the number of gates grouped in the class.
void add_h_to_front(int target_qbit)
Add a Hadamard gate to the front of the list of gates.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
std::vector< Gate * > gates
The list of stored gates.
A class representing a CROT gate.
void add_x_to_front(int target_qbit)
Add a X gate to the front of the list of gates.
void add_sx_to_front(int target_qbit)
Add a SX gate to the front of the list of gates.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*Gate.
A class representing a CZ operation.
Header file for a class representing a CNOT operation.
std::vector< int > block_end
A class containing basic methods for setting up the verbosity level.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
void add_y_to_front(int target_qbit)
Add a Y gate to the front of the list of gates.
A class representing a U3 gate.
void add_syc(int target_qbit, int control_qbit)
Append a Sycamore gate (i.e.
A class representing a RZ gate.
gate_type type
The type of the operation (see enumeration gate_type)
int get_parameter_num()
Call to get the number of free parameters.
double get_second_Renyi_entropy(Matrix_real ¶meters_mtx, Matrix &input_state, matrix_base< int > &qbit_list)
Call to evaluate the seconf Rényi entropy.
void add_syc_to_front(int target_qbit, int control_qbit)
Add a Sycamore gate (i.e.
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
void add_ch(int target_qbit, int control_qbit)
Append a CH gate (i.e.
A class representing a CRY gate.
virtual void apply_from_right(Matrix &input)
Call to apply the gate on the input array/matrix by input*Gate.
int rows
The number of rows.
A class representing a CH operation.
int cols
The number of columns.
Header file for a class representing a rotation gate around the Z axis.
void add_ch_to_front(int target_qbit, int control_qbit)
Add a CH gate (i.e.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void add_composite()
Append a Composite gate to the list of gates.
Header file for a class representing the Hadamard gate.
virtual Matrix calc_one_qubit_u3(double Theta, double Phi, double Lambda)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
void add_u2_to_front(int target_qbit)
Add a U2 gate to the front of the list of gates.
gate_type get_type()
Call to get the type of the operation.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void add_u3(int target_qbit)
Append a U3 gate to the list of gates.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
void add_rz(int target_qbit)
Append a RZ gate to the list of gates.
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
void apply_to(Matrix &input)
Call to apply the gate on the input array/matrix by U3*input.
void add_y(int target_qbit)
Append a Y gate to the list of gates.
void reset_dependency_graph()
Method to reset the dependency graph of the gates in the circuit.
void combine(Gates_block *op_block)
Call to append the gates of an gate block to the current block.
void add_ry(int target_qbit)
Append a RY gate to the list of gates.
void set_control_qbit(int control_qbit_in)
Call to set the control qubit for the gate operation.
void set_parameter_start_idx(int start_idx)
Call to set the starting index of the parameters in the parameter array corresponding to the circuit ...
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
Header file for a class representing a CZ operation.
int get_parameter_start_idx()
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
void add_parent(Gate *parent)
Call to add a parent gate to the current gate.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
void set_target_qbit(int target_qbit_in)
Call to set the target qubit for the gate operation.
void add_on()
Append a ON gate to the list of gates.
Structure type representing complex numbers in the SQUANDER package.
A class representing a CNOT operation.
int verbose
Set the verbosity level of the output messages.
virtual std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*CRY.
void clear_parents()
Call to erase data on parents.
void determine_children(Gate *gate)
Call to obtain the child gates in the circuit.
void add_u1_to_front(int target_qbit)
Add a U1 gate to the front of the list of gates.
int extract_gates(Gates_block *op_block)
Call to extract the gates stored in the class.
void add_cry_to_front(int target_qbit, int control_qbit)
Add a CRY gate to the front of the list of gates.
int Power_of_2(int n)
Calculates the n-th power of 2.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
virtual Gates_block * clone()
Create a clone of the present class.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
virtual void apply_from_right(Matrix_real ¶meters_mtx, Matrix &input)
Call to apply the gate on the input array/matrix by input*CNOT.
bool contains_adaptive_gate()
Call to determine, whether the circuit contains daptive gate or not.
Class to store data of complex arrays and its properties.
void add_gates_to_front(std::vector< Gate *> gates_in)
Add an array of gates to the front of the list of gates.
void add_gate_to_front(Gate *gate)
Add an gate to the front of the list of gates.
A class representing a Hadamard gate.
A class representing a U3 gate.
void add_z(int target_qbit)
Append a Z gate to the list of gates.
Header file for a class representing a U2 gate.
Header file for a class representing a gate used in adaptive decomposition.
A class representing a U3 gate.
int size() const
Call to get the number of the allocated elements.
void add_cry(int target_qbit, int control_qbit)
Append a CRY gate to the list of gates.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
Gates_block()
Default constructor of the class.
void add_rx_to_front(int target_qbit)
Add a RX gate to the front of the list of gates.
A class representing a CRY gate.
int get_parameter_num()
Call to get the number of free parameters.
void add_tdg_to_front(int target_qbit)
Add a Tdg gate to the front of the list of gates.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Header file for a class representing a U3 gate.
void add_tdg(int target_qbit)
Append a Tdg gate to the list of gates.
A class representing a CZ operation.
void add_u3_to_front(int target_qbit)
Add a U3 gate to the front of the list of gates.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
std::string name
A string labeling the gate operation.
void add_cz(int target_qbit, int control_qbit)
Append a CZ gate gate to the list of gates.
A class representing a U3 gate.
std::vector< Gate * > children
list of child gates to be applied after this current gate
Fixed point data related to a gate operation.
bool is_qbit_present(std::vector< int > involved_qubits, int new_qbit, int num_of_qbits)
Call to check whether the given qubit is involved in the sub-circuit or not.
int get_target_qbit()
Call to get the index of the target qubit.
std::vector< int > remove_list_intersection(std::vector< int > &list1, std::vector< int > &list2)
Call to remove those integer elements from list1 which are present in list.
Header file for a class representing a rotation gate around the X axis.
Base class for the representation of general gate operations.
Base class for the representation of general gate operations.
Header file for a class representing a rotation gate around the Y axis.
std::string get_name()
Call to get the name label of the gate.
virtual std::vector< int > get_involved_qubits()
Call to get the qubits involved in the gate operation.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
void add_gate_nums(std::map< std::string, int > &gate_nums)
Call to add the number of the individual gate types in the circuit to the map given in the argument...
int get_limit()
???????????
void add_ry_to_front(int target_qbit)
Add a RY gate to the front of the list of gates.
int parameter_num
the number of free parameters of the operation
virtual ~Gates_block()
Destructor of the class.
virtual void apply_to_list(std::vector< Matrix > &inputs, int parallel)
Call to apply the gate on a list of inputs.
void add_rx(int target_qbit)
Append a RX gate to the list of gates.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*Gate.
Matrix calc_one_qubit_u3(double PhiOver2)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
double activation_function(double Phi, int limit)
?????
void add_un()
Append a UN gate to the list of gates.
void export_gate_list_to_binary(Matrix_real ¶meters, Gates_block *gates_block, const std::string &filename, int verbosity)
?????????
Matrix copy()
Call to create a copy of the matrix.
A class representing a SYC operation.
void insert_gate(Gate *gate, int idx)
Call to insert a gate at a given position.
void add_unique_elelement(std::vector< int > &involved_qbits, int qbit)
Add an integer to a vector of integers if the integer is not already an element of the vector...
double real
the real part of a complex number
virtual Matrix_real extract_parameters(Matrix_real ¶meters)
Call to extract parameters from the parameter array corresponding to the circuit, in which the gate i...
void reset_parameter_start_indices()
Method to reset the parameter start indices of gate operations incorporated in the circuit...
A class representing a CRY gate.
Header file for a class representing the Z gate.
int qbit_num
number of qubits spanning the matrix of the operation
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
void add_t_to_front(int target_qbit)
Add a T gate to the front of the list of gates.
A class representing a U3 gate.
void add_crot(int target_qbit, int control_qbit)
Append a CROT gate gate to the list of gates.
void add_crot_to_front(int target_qbit, int control_qbit)
Add a CROT gate gate to the front of the list of gates.
int get_qbit_num()
Call to get the number of qubits composing the unitary.
gate_type
Type definition of operation types (also generalized for decomposition classes derived from the class...
A class representing a U3 gate.
Gate * get_gate(int idx)
Call to get the gates stored in the class.
void add_cr_to_front(int target_qbit, int control_qbit)
Add a CR gate to the front of the list of gates.
Base class for the representation of general gate operations.
A class representing a U3 gate.
virtual void apply_to(Matrix &input, int parallel)
Call to apply the gate on the input array/matrix.
void list_gates(const Matrix_real ¶meters, int start_index)
Call to print the list of gates stored in the block of gates for a specific set of parameters...
Matrix get_reduced_density_matrix(Matrix_real ¶meters_mtx, Matrix &input_state, matrix_base< int > &qbit_list_subset)
Call to evaluate the reduced densiy matrix.
void add_adaptive_to_front(int target_qbit, int control_qbit)
Add a Adaptive gate to the front of the list of gates.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void add_gates(std::vector< Gate *> gates_in)
Append a list of gates to the list of gates.
Header file for a class representing a U1 gate.
Matrix_real inverse_reverse_parameters(const Matrix_real ¶meters_in, std::vector< Gate *>::iterator gates_it, int num_of_gates)
Call to inverse-reverse the order of the parameters in an array.
void add_t(int target_qbit)
Append a T gate to the list of gates.
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
int get_control_qbit()
Call to get the index of the control qubit.
Class to store data of complex arrays and its properties.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
double imag
the imaginary part of a complex number
void add_sx(int target_qbit)
Append a SX gate to the list of gates.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the gates stored in the block of gates.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U2.
Header file for a class representing a Sycamore gate.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.