Skip to content

Commit 907524d

Browse files
authored
Merge pull request #222 from OriginQ/develop
Develop
2 parents 8a13a20 + f252601 commit 907524d

File tree

914 files changed

+27546
-196951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

914 files changed

+27546
-196951
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ before_script:
2525
- cmake . ${TRAVIS_BUILD_DIR}
2626
- make clean
2727
- make
28-
script: echo ok
28+
script: echo ok

Applications/B_V_Algorithm/BernsteinVaziraniAlgorithm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2021 Origin Quantum Computing. All Right Reserved.
2+
Copyright (c) 2017-2023 Origin Quantum Computing. All Right Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

Applications/ChemiQCalc/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.1)
22
project(ChemiQCalc)
33
file(GLOB_RECURSE CHEMIQ_CALC_CPP ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
44
add_executable(${PROJECT_NAME} ${CHEMIQ_CALC_CPP})
5-
target_link_libraries(${PROJECT_NAME} ${LIB_QALG})
5+
target_link_libraries(${PROJECT_NAME} ${LIB_QALG} pybind11::embed)
66

77
set(TEST_SCRIPT "script.py")
88
add_custom_command(OUTPUT ${TEST_SCRIPT}
99
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_SCRIPT}
1010
)
11-
add_custom_target(CopyTestSript ALL DEPENDS ${TEST_SCRIPT})
11+
add_custom_target(CopyTestSript ALL DEPENDS ${TEST_SCRIPT})

Applications/DJ_Algorithm/DJ_Algorithm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2020 Origin Quantum Computing. All Right Reserved.
2+
Copyright (c) 2017-2023 Origin Quantum Computing. All Right Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

Applications/Grover_Algorithm/Grover_Algorithm.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2020 Origin Quantum Computing. All Right Reserved.
2+
Copyright (c) 2017-2023 Origin Quantum Computing. All Right Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -159,7 +159,7 @@ static uint32_t quantum_walk_search(const std::vector<uint32_t>& search_space, c
159159
QVec measure_qubits;
160160
uint32_t qubit_size = 0;
161161
vector<ClassicalCondition> c;
162-
const double max_repeat = 3.1415926 * sqrt(((double)search_space.size()) / ((double)search_result_for_check.size())) / 4.0;
162+
// const double max_repeat = 3.1415926 * sqrt(((double)search_space.size()) / ((double)search_result_for_check.size())) / 4.0;
163163
while (true)
164164
{
165165
measure_qubits.clear();

Applications/HHL_Algorithm/HHL_Algorithm.cpp

+47-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2020 Origin Quantum Computing. All Right Reserved.
2+
Copyright (c) 2017-2023 Origin Quantum Computing. All Right Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -22,8 +22,9 @@ limitations under the License.
2222
using namespace std;
2323
using namespace QPanda;
2424

25-
static uint32_t g_precision = 0;
25+
extern std::string noise_json;
2626
static string g_hhl_data_file;
27+
static uint32_t g_precision = 0;
2728
static const string g_result_file_prefix = "HHL_result_";
2829

2930
static uint32_t load_data_file(const std::string& data_file, std::vector<double>& A, std::vector<double>& b)
@@ -58,21 +59,21 @@ static uint32_t load_data_file(const std::string& data_file, std::vector<double>
5859
{
5960
break;
6061
}
61-
62+
6263
}
6364

6465
auto _data_str = line_str.substr(offset, _pos_1 - offset);
6566
//trim(complex_data_str);
6667
offset = _pos_1 + 1;
67-
if (_data_str.length() == 0){
68+
if (_data_str.length() == 0) {
6869
continue;
6970
}
7071

71-
const auto _c = _data_str.at(0);
72-
if((_c < '0' || _c > '9') && (_c != '-'))
73-
{
74-
break;
75-
}
72+
const auto _c = _data_str.at(0);
73+
if ((_c < '0' || _c > '9') && (_c != '-'))
74+
{
75+
break;
76+
}
7677

7778
data_vec.push_back(atof(_data_str.c_str()));
7879
}
@@ -83,14 +84,14 @@ static uint32_t load_data_file(const std::string& data_file, std::vector<double>
8384
uint32_t A_dimension = 0;
8485
bool b_read_A_end = false;
8586
while (getline(data_file_reader, line_data)) {
86-
if (b_read_A_end){
87+
if (b_read_A_end) {
8788
get_line_data_fun(line_data, b);
8889
break;
8990
}
90-
else{
91+
else {
9192
get_line_data_fun(line_data, A);
9293
}
93-
94+
9495
if (++line_index == 1)
9596
{
9697
A_dimension = A.size();
@@ -123,18 +124,18 @@ static void HHL_run(const std::string& data_file)
123124
std::vector<double> b;
124125
uint32_t A_dimension = load_data_file(data_file, A, b);
125126
MatrixXd A_bad(b.size(), b.size());
126-
VectorXd b_bad(b.size());
127+
VectorXd b_bad(b.size());
127128
for (int i = 0; i < b.size(); ++i) {
128-
for (int j = 0; j < b.size(); ++j) {
129-
A_bad(i, j) = A[i * b.size() + j];
130-
}
131-
b_bad(i) = b[i];
129+
for (int j = 0; j < b.size(); ++j) {
130+
A_bad(i, j) = A[i * b.size() + j];
131+
}
132+
b_bad(i) = b[i];
132133
}
133134

134135
//A'
135136
MatrixXd M;
136137
auto result = DynamicSparseApproximateInverse(A_bad, b_bad, 0.2, b.size(), M);
137-
MatrixXd A_prime(2*b.size(), 2*b.size());
138+
MatrixXd A_prime(2 * b.size(), 2 * b.size());
138139
A_prime.topLeftCorner(b.size(), b.size()) = A_prime.bottomRightCorner(b.size(), b.size()) = MatrixXd::Zero(4, 4);
139140
A_prime.topRightCorner(b.size(), b.size()) = result.first;
140141
A_prime.bottomLeftCorner(b.size(), b.size()) = result.first.transpose();
@@ -144,19 +145,19 @@ static void HHL_run(const std::string& data_file)
144145
std::vector<double> b2;
145146
for (int i = 0; i < b_good.size(); ++i)
146147
{
147-
b2.push_back(b_good(i));
148+
b2.push_back(b_good(i));
148149
}
149150

150151
std::vector<double> b_prime;
151152
for (int i = 0; i < b.size(); ++i)
152-
b_prime.push_back(b2[i]);
153+
b_prime.push_back(b2[i]);
153154
for (int i = 0; i < b.size(); ++i)
154-
b_prime.push_back(0);
155+
b_prime.push_back(0);
155156

156157
auto A_prime_mat = Eigen_to_QStat(A_prime);
157158

158159
QStat Q_A;
159-
for (const auto& i : A){
160+
for (const auto& i : A) {
160161
Q_A.push_back(i);
161162
}
162163

@@ -175,19 +176,19 @@ static void HHL_run(const std::string& data_file)
175176
if (_file_name_pos == (std::numeric_limits<size_t>::max)())
176177
{
177178
_file_name_pos = g_hhl_data_file.find_last_of('\\');
178-
if (_file_name_pos == (std::numeric_limits<size_t>::max)()){
179+
if (_file_name_pos == (std::numeric_limits<size_t>::max)()) {
179180
_file_name_pos = 0;
180181
}
181182
}
182183

183184
string output_file;
184-
if (0 == _file_name_pos){
185+
if (0 == _file_name_pos) {
185186
output_file = g_result_file_prefix + g_hhl_data_file;
186187
}
187-
else{
188+
else {
188189
output_file = g_result_file_prefix + g_hhl_data_file.substr(_file_name_pos + 1);
189190
}
190-
191+
191192
ofstream outfile(ofstream(output_file, ios::out | ios::binary));
192193
if (!outfile.is_open())
193194
{
@@ -196,7 +197,7 @@ static void HHL_run(const std::string& data_file)
196197

197198
cout << "HHL_result of " << g_hhl_data_file << ": " << A_dimension << "-dimensional matrix:\n";
198199
outfile << "HHL_result of " << g_hhl_data_file << ": " << A_dimension << "-dimensional matrix:\n";
199-
for (int i = result_prime.size()/2; i < result_prime.size(); ++i)
200+
for (int i = result_prime.size() / 2; i < result_prime.size(); ++i)
200201
{
201202
std::cout << result_prime[i] << " ";
202203
outfile << _tostring(result_prime[i].real()).c_str() << ", " << _tostring(result_prime[i].imag());
@@ -210,14 +211,14 @@ static void HHL_run(const std::string& data_file)
210211
std::cout << std::endl;
211212
outfile << std::endl;
212213
if (outfile.is_open()) { outfile.close(); }
213-
214+
214215
return;
215216
}
216217

217218
int main(int argc, char* argv[])
218219
{
219-
const std::string parameter_descr_str = R"(
220-
Version: 2.2
220+
std::cout << "Version: 2.3.220713" << std::endl;
221+
const std::string parameter_descr_str = R"(
221222
The legal parameter form is as follows:
222223
HHL_Algorithm [data-file] [precision]
223224
data-file: configure A and b for linear-system-equation: Ax=b.
@@ -240,16 +241,26 @@ int main(int argc, char* argv[])
240241
)";
241242

242243
//std::string data_file = "data.txt";
243-
#if 0
244+
#if 1
244245
try
245246
{
246-
if (argc == 3){
247+
if (argc == 3) {
247248
g_hhl_data_file = argv[1];
248249
g_precision = atoi(argv[2]);
249-
cout << "got param, data file: " << g_hhl_data_file <<
250-
", precision: " << 1.0/(double)pow(10, g_precision) << endl;
250+
cout << "got param, data file: " << g_hhl_data_file <<
251+
", precision: " << 1.0 / (double)pow(10, g_precision) << endl;
251252
}
252-
else{
253+
else if (argc == 4)
254+
{
255+
noise_json = argv[3];
256+
g_hhl_data_file = argv[1];
257+
g_precision = atoi(argv[2]);
258+
cout << "got param, data file: " << g_hhl_data_file <<
259+
", precision: " << 1.0 / (double)pow(10, g_precision) << endl;
260+
261+
std::cout << "noise file:" << noise_json << std::endl;
262+
}
263+
else {
253264
QCERR_AND_THROW(init_fail, "Error: parameter error: Incomplete parameters.");
254265
}
255266
}
@@ -266,8 +277,6 @@ int main(int argc, char* argv[])
266277

267278
HHL_run(g_hhl_data_file);
268279

269-
cout << "HHL_Algorithm run over, press Enter to continue." << endl;
270-
getchar();
271-
280+
cout << "HHL_Algorithm run over." << endl;
272281
return 0;
273282
}

0 commit comments

Comments
 (0)