Skip to content

Commit cb65c71

Browse files
authored
Merge pull request #29 from xsuite/release/v0.5.0
Release 0.5.0
2 parents a7600b4 + b45caec commit cb65c71

File tree

8 files changed

+103
-30
lines changed

8 files changed

+103
-30
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Xboinc is a package within the Xsuite project that provides tools for easily submit and manage tracking jobs on the BOINC computing platform. It is designed to streamline the process of job submission, management, and monitoring for users of the Xsuite framework in need for large-scale computing resources, with a project adaptable to volunteer-based computing. Note that the services provided by this package are available only to CERN users with a valid computing account.
44

5-
**NOTE: CURRENTLY, ONLY THE DEVELOPMENT SERVER IS AVAILABLE! Be sure to always set the `dev_server` parameter to `True` when using the package!**
6-
75
# How to use Xboinc
86

97
## Install Xboinc
@@ -81,7 +79,7 @@ job_manager = xb.JobSubmitter(
8179
user="mycernshortname",
8280
study_name="a_relevant_study_name",
8381
line=line,
84-
dev_server=True # currently, the dev server is the only one available
82+
dev_server=False, # set to True to use the Xboinc development server (for testing purposes only), by default False
8583
)
8684

8785
# prepare a big batch of particles
@@ -114,7 +112,7 @@ When the jobs are completed, the Xboinc server will store the results in your al
114112
```python
115113
import xboinc as xb
116114

117-
for job_name, job_metadata, result_particles in xb.JobRetriever.iterate("mycernshortname", "a_relevant_study_name", dev_server=True):
115+
for job_name, job_metadata, result_particles in xb.JobRetriever.iterate("mycernshortname", "a_relevant_study_name"):
118116
print(f"Job {job_name} completed with particles: {result_particles.to_dict()}")
119117
print(f"Job metadata: {job_metadata}")
120118

@@ -132,7 +130,7 @@ print(xb.check_user_subscription("mycernshortname"))
132130
# Query the registered work units for the user
133131
print("What are my jobs?")
134132
# Probes the work units for the user registered in this Xboinc installation
135-
print(xb.query_registered_work_units(dev_server=True))
133+
print(xb.query_registered_work_units())
136134
```
137135

138136
Other convenience functions are available in the `xboinc` package, be sure to inspect the API documentation and docstrings for more details!

pin_xsuite_versions.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ cd ..
2222
echo "The following modules will be pinned:"
2323
for module in $modules; do
2424
version=$(python -c "import $module; print($module.__version__)")
25-
2625
if [[ -z "$version" ]]; then
2726
echo "Error: Could not retrieve version for $module"
2827
exit 1
2928
fi
30-
3129
echo " - ${module}: $version"
3230
done
3331

@@ -49,19 +47,33 @@ esac
4947
echo "Updating version information in configuration files..."
5048
for module in $modules; do
5149
version=$(python -c "import $module; print($module.__version__)")
52-
5350
if [[ -z "$version" ]]; then
5451
echo "Error: Could not retrieve version for $module"
5552
exit 1
5653
fi
57-
58-
# Update version in three different files with appropriate patterns
59-
sed -i "s/\('${module}' *:\).*/\1 '${version}',/" xboinc/general.py
60-
sed -i "s/\('${module}' *:\).*/\1 '${version}',/" tests/test_version.py
61-
sed -i "s/\(${module} *=\).*/\1 '==${version}'/" pyproject.toml
62-
54+
if [[ "$OSTYPE" == "darwin"* ]]
55+
then
56+
# Update version in three different files with appropriate patterns
57+
sed -i '' "s/\('"${module}"' *:\).*/\1 '"${version}"',/" xboinc/general.py
58+
sed -i '' "s/\("${module}" *=\).*/\1 '=="${version}"'/" pyproject.toml
59+
sed -i '' "s/\('"${module}"' *:\).*/\1 '"${version}"'/" tests/test_version.py
60+
else
61+
# Update version in three different files with appropriate patterns
62+
sed -i "s/\('"${module}"' *:\).*/\1 '"${version}"',/" xboinc/general.py
63+
sed -i "s/\("${module}" *=\).*/\1 '=="${version}"'/" pyproject.toml
64+
sed -i "s/\('"${module}"' *:\).*/\1 '"${version}"'/" tests/test_version.py
65+
fi
6366
echo " - Pinned ${module} to version ${version}"
6467
done
6568

69+
# ----- Update app version in C source -----
70+
appver=$(python -c "import xboinc; print(xboinc.app_version_int)")
71+
if [[ "$OSTYPE" == "darwin"* ]]
72+
then
73+
sed -i '' "s/\(int64_t xboinc_exec_version =\).*/\1 "${appver}";/" xboinc/executable/version.h
74+
else
75+
sed -i "s/\(int64_t xboinc_exec_version =\).*/\1 "${appver}";/" xboinc/executable/version.h
76+
fi
77+
6678
echo "Version pinning completed successfully."
6779
exit 0

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[tool.poetry]
77
name = "xboinc"
8-
version = "0.4.3"
8+
version = "0.5.0"
99
description = "Xsuite BOINC interface"
1010
homepage = "https://github.com/xsuite/xboinc"
1111
repository = "https://github.com/xsuite/xboinc"
@@ -24,7 +24,7 @@ include = [ "LICENSE", "NOTICE" ]
2424
python = '>=3.9'
2525
numpy = '>=1.0'
2626
packaging = '>=23.0'
27-
xobjects = ">=0.5.0"
27+
xobjects = ">=0.5.3"
2828
xdeps = '==0.10.5'
2929
xpart = '==0.23.0'
3030
xtrack = '==0.84.7'

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def test_version():
15-
assert __version__ == '0.4.3'
15+
assert __version__ == '0.5.0'
1616

1717

1818
def test_xb_ver():

xboinc/executable/main.cpp

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
#ifdef __cplusplus
1515
#include <cstdio>
16+
#include <chrono>
1617
#include <cstdint>
1718
#include <cstdlib>
1819
#include <cstring>
1920
#include <cmath>
2021
#include <cstdarg>
22+
#include <functional>
2123
#else
2224
#include <stdio.h>
2325
#include <stdint.h>
@@ -73,7 +75,7 @@ int8_t early_sleep = 0;
7375
int8_t trickle_up = 0;
7476
int8_t trickle_down = 0;
7577
int8_t critical_section = 0; // run most of the time in a critical section
76-
int8_t report_fraction_done = 0;
78+
int8_t report_fraction_done = 1;
7779
int8_t network_usage = 0;
7880
double cpu_time = 20, comp_result;
7981
int8_t verbose = 0;
@@ -85,6 +87,70 @@ static FILE* XB_fopen_allow_null(char *filename, const char *mode);
8587
static int8_t* XB_file_to_buffer(FILE *fid, int8_t *buf_in);
8688
static int XB_do_checkpoint(XbInput xb_input, XbState xb_state);
8789

90+
class ThrottledReporter
91+
{
92+
public:
93+
using Clock = std::chrono::steady_clock;
94+
95+
// interval: minimum time between reports
96+
// report: void(double fraction_done)
97+
// check_every: only check the clock every N calls (must be power of two for fast masking)
98+
// report_first: if true, allow the very first call to report immediately
99+
ThrottledReporter(std::chrono::seconds interval,
100+
std::function<void(double)> report,
101+
uint32_t check_every = 32,
102+
bool report_first = true)
103+
: interval_(interval),
104+
report_(std::move(report)),
105+
mask_(check_every - 1),
106+
report_first_(report_first),
107+
last_(Clock::now())
108+
{
109+
// Ensure check_every is a power of two (optional assert in debug)
110+
// assert((check_every & (check_every - 1)) == 0 && "check_every must be power of two");
111+
if (report_first_)
112+
last_ -= interval_; // so first eligible call will pass immediately
113+
}
114+
115+
inline void maybe_report(double fraction_done)
116+
{
117+
// Amortize clock reads
118+
if ((++calls_ & mask_) != 0)
119+
return;
120+
121+
auto now = Clock::now();
122+
if (now - last_ >= interval_)
123+
{
124+
last_ = now;
125+
report_(fraction_done);
126+
}
127+
}
128+
129+
// If you want to force a final update at the end:
130+
inline void flush(double fraction_done)
131+
{
132+
report_(fraction_done);
133+
last_ = Clock::now();
134+
}
135+
136+
private:
137+
std::chrono::seconds interval_;
138+
std::function<void(double)> report_;
139+
uint32_t mask_;
140+
bool report_first_;
141+
Clock::time_point last_;
142+
uint32_t calls_ = 0;
143+
};
144+
145+
ThrottledReporter prog(std::chrono::seconds(1), [](double fd)
146+
{
147+
XB_fprintf(2, stdout, "Percentage done: %f%%\n", fd * 100.);
148+
#ifdef COMPILE_TO_BOINC
149+
boinc_fraction_done(fd);
150+
#endif
151+
},
152+
/*check_every=*/32, // read the clock every 32 iterations
153+
/*report_first=*/true);
88154

89155
int main(int argc, char **argv){
90156
int retval;
@@ -258,13 +324,9 @@ int main(int argc, char **argv){
258324
boinc_checkpoint_completed();
259325
#endif
260326
}
261-
#ifdef COMPILE_TO_BOINC
262327
if (report_fraction_done) {
263-
double fd = (int)current_turn / (int)num_turns;
264-
if (cpu_time) fd /= 2;
265-
boinc_fraction_done(fd);
328+
prog.maybe_report((double)current_turn / (double)num_turns);
266329
}
267-
#endif
268330
}
269331
// End main loop ===========
270332
// ==========================
@@ -276,6 +338,7 @@ int main(int argc, char **argv){
276338
XbInput_get_xb_state__xsize(xb_input), outfile);
277339
fclose(outfile);
278340

341+
prog.flush(1.0);
279342
#ifdef COMPILE_TO_BOINC
280343
// BOINC clean up
281344
// if (trickle_up) {
@@ -289,7 +352,7 @@ int main(int argc, char **argv){
289352
// XB_fprintf(0, stderr, "Got trickle-down message: %s\n", buf);
290353
// }
291354
// }
292-
boinc_fraction_done(1);
355+
// boinc_fraction_done(1);
293356
boinc_finish(0);
294357
#endif
295358

xboinc/executable/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Do not change
2020
// =============================================================================
2121
// version XXX.YYY as int (no patch)
22-
const int64_t xboinc_exec_version = 4;
22+
const int64_t xboinc_exec_version = 5;
2323
// =============================================================================
2424

2525
#endif /* XB_EXECUTABLE_VERSION_H */

xboinc/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Do not change
1313
# ==============================================================================
1414

15-
__version__ = '0.4.3'
15+
__version__ = '0.5.0'
1616

1717
# These are the xsuite modules that are used by boinc and the versions they are
1818
# tied to. This will be automatically updated from the active environment when

xboinc/submit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ def __init__(self, user, study_name, line=None, dev_server=False, **kwargs):
152152
"""
153153

154154
assert_versions()
155-
if not dev_server:
156-
raise NotImplementedError(
157-
"Regular server not yet operational. " + "Please use dev_server=True."
158-
)
155+
# if not dev_server:
156+
# raise NotImplementedError(
157+
# "Regular server not yet operational. " + "Please use dev_server=True."
158+
# )
159159
self.dev_server = dev_server
160160
if "__" in study_name:
161161
raise ValueError(

0 commit comments

Comments
 (0)