Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for release v0.1 #109

Merged
merged 13 commits into from
Aug 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ We need another process to start Jupyter Notebook/JupyterLab and connect to liby
4. Launch Jupyter Notebook/JupyterLab
```bash
jupyter notebook # launch Jupyter Notebook
jupyter-lab # launch JupyterLab
jupyter lab # launch JupyterLab
```
5. Click `Libyt` to connect to libyt kernel once the simulation is running and libyt kernel is activated.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Please go through [Login Node](#login-node) before going through [Local Laptop](
2. Launch Jupyter Notebook / JupyterLab in no-browser mode with port `XXXX` and allowing access from other IP address (`--ip="0.0.0.0"`):
```bash
jupyter notebook --no-browser --port=XXXX --ip="0.0.0.0"
jupyter-lab --no-browser --port=XXXX --ip="0.0.0.0"
jupyter lab --no-browser --port=XXXX --ip="0.0.0.0"
```
Change `XXXX` to some unused port on login node, this is just a placeholder.
3. You should see something like:
Expand Down
4 changes: 4 additions & 0 deletions example/amr-example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ int main(int argc, char* argv[]) {
yt_set_UserParameterInt("mhd", 1, &mhd);
const int srhd = 0;
yt_set_UserParameterInt("srhd", 1, &srhd);
const int opt_unit = 0;
yt_set_UserParameterInt("opt_unit", 1, &opt_unit);
const float mu = 0.6;
yt_set_UserParameterFloat("mu", 1, &mu);

// demo of some other parameters we can add
const int user_int = 1;
Expand Down
9 changes: 9 additions & 0 deletions example/quick-start/quick-start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ int main(int argc, char* argv[]) {
// Execute Python functions and activate Python entry points
// ==========================================================
if (yt_run_Function("print_hello_world") != YT_SUCCESS) {
fprintf(stderr, "ERROR: yt_run_Function failed!\n");
exit(EXIT_FAILURE);
}

if (yt_run_FunctionArguments("print_args", 3, "\'1\'", "2", "3.0") != YT_SUCCESS) {
fprintf(stderr, "ERROR: yt_run_FunctionArguments failed!\n");
exit(EXIT_FAILURE);
}

// Activate Python prompt
if (yt_run_InteractiveMode("LIBYT_STOP") != YT_SUCCESS) {
fprintf(stderr, "ERROR: yt_run_InteractiveMode failed!\n");
exit(EXIT_FAILURE);
}

Expand All @@ -67,6 +70,12 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}

// Free and reset the state
if (yt_free() != YT_SUCCESS) {
fprintf(stderr, "ERROR: yt_free() failed!\n");
exit(EXIT_FAILURE);
}

// =======================================
// Finalize libyt
// =======================================
Expand Down
6 changes: 0 additions & 6 deletions src/append_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ static int set_particle_data(yt_grid* grid);
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int append_grid(yt_grid* grid) {
SET_TIMER(__PRETTY_FUNCTION__);

// export grid info to libyt.hierarchy
PyArrayObject* py_array_obj;

Expand Down Expand Up @@ -76,8 +74,6 @@ int append_grid(yt_grid* grid) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
static int set_field_data(yt_grid* grid) {
SET_TIMER(__PRETTY_FUNCTION__);

yt_field* field_list = LibytProcessControl::Get().field_list;

PyObject *py_grid_id, *py_field_labels, *py_field_data;
Expand Down Expand Up @@ -179,8 +175,6 @@ static int set_field_data(yt_grid* grid) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
static int set_particle_data(yt_grid* grid) {
SET_TIMER(__PRETTY_FUNCTION__);

yt_particle* particle_list = LibytProcessControl::Get().particle_list;

PyObject *py_grid_id, *py_ptype_labels, *py_attributes, *py_data;
Expand Down
14 changes: 0 additions & 14 deletions src/get_dtype_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_npy_dtype(yt_dtype data_type, int* npy_dtype) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (data_type) {
case YT_FLOAT:
*npy_dtype = NPY_FLOAT;
Expand Down Expand Up @@ -103,8 +101,6 @@ int get_npy_dtype(yt_dtype data_type, int* npy_dtype) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_yt_dtype_from_npy(int npy_dtype, yt_dtype* data_dtype) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (npy_dtype) {
case NPY_FLOAT:
*data_dtype = YT_FLOAT;
Expand Down Expand Up @@ -173,8 +169,6 @@ int get_yt_dtype_from_npy(int npy_dtype, yt_dtype* data_dtype) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_mpi_dtype(yt_dtype data_type, MPI_Datatype* mpi_dtype) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (data_type) {
case YT_FLOAT:
*mpi_dtype = MPI_FLOAT;
Expand Down Expand Up @@ -258,8 +252,6 @@ int get_mpi_dtype(yt_dtype data_type, MPI_Datatype* mpi_dtype) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_dtype_size(yt_dtype data_type, int* dtype_size) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (data_type) {
case YT_FLOAT:
*dtype_size = sizeof(float);
Expand Down Expand Up @@ -343,8 +335,6 @@ int get_dtype_size(yt_dtype data_type, int* dtype_size) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_dtype_typeid(yt_dtype data_type, const std::type_info** dtype_id) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (data_type) {
case YT_FLOAT:
*dtype_id = &typeid(float);
Expand Down Expand Up @@ -430,8 +420,6 @@ int get_dtype_typeid(yt_dtype data_type, const std::type_info** dtype_id) {
// Return : YT_SUCCESS or YT_FAIL
//-------------------------------------------------------------------------------------------------------
int get_dtype_allocation(yt_dtype data_type, unsigned long length, void** data_ptr) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (data_type) {
case YT_FLOAT:
*data_ptr = malloc(length * sizeof(float));
Expand Down Expand Up @@ -532,8 +520,6 @@ int get_dtype_allocation(yt_dtype data_type, unsigned long length, void** data_p
//-------------------------------------------------------------------------------------------------------
int big_MPI_Get_dtype(void* recv_buff, long data_len, yt_dtype* data_dtype, MPI_Datatype* mpi_dtype, int get_rank,
MPI_Aint base_address, MPI_Win* window) {
SET_TIMER(__PRETTY_FUNCTION__);

switch (*data_dtype) {
case YT_FLOAT:
return big_MPI_Get<float>(recv_buff, data_len, mpi_dtype, get_rank, base_address, window);
Expand Down
12 changes: 6 additions & 6 deletions src/libyt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void LibytKernel::configure_impl() {

PyObject* py_module_jedi = PyImport_ImportModule("jedi");
if (py_module_jedi == NULL) {
log_info("Unable to import jedi, jedi auto-completion library is disabled\n");
log_info("See https://jedi.readthedocs.io/ \n");
log_info(
"Unable to import jedi, jedi auto-completion library is disabled (See https://jedi.readthedocs.io/)\n");
m_py_jedi_interpreter = NULL;
} else {
m_py_jedi_interpreter = PyObject_GetAttrString(py_module_jedi, "Interpreter");
Expand Down Expand Up @@ -68,7 +68,7 @@ nl::json LibytKernel::execute_request_impl(int execution_counter, const std::str
bool store_history, nl::json user_expressions, bool allow_stdin) {
SET_TIMER(__PRETTY_FUNCTION__);

std::string cell_name = std::string("In [") + std::to_string(execution_counter) + std::string("]");
std::string cell_name = std::string("<In [") + std::to_string(execution_counter) + std::string("]>");

// Find if '%' is the first non-space character, if so, redirect jobs to define command
std::size_t found = code.find_first_not_of("\t\n\v\f\r ");
Expand Down Expand Up @@ -187,8 +187,8 @@ nl::json LibytKernel::complete_request_impl(const std::string& code, int cursor_

// Check if jedi has successfully import
if (m_py_jedi_interpreter == NULL) {
log_info("Unable to import jedi, jedi auto-completion library is disabled\n");
log_info("See https://jedi.readthedocs.io/ \n");
log_info(
"Unable to import jedi, jedi auto-completion library is disabled (See https://jedi.readthedocs.io/)\n");
return xeus::create_complete_reply({}, cursor_pos, cursor_pos);
}

Expand Down Expand Up @@ -325,7 +325,7 @@ nl::json LibytKernel::kernel_info_request_impl() {
// helper
libyt_kernel_info["help_links"] = nl::json::array();
libyt_kernel_info["help_links"][0] =
nl::json::object({{"text", "libyt Kernel Documents"}, {"url", "https://yt-project.github.io/libyt/"}});
nl::json::object({{"text", "libyt Kernel Documents"}, {"url", "https://libyt.readthedocs.io/en/latest/"}});

// status
libyt_kernel_info["status"] = "ok";
Expand Down
3 changes: 3 additions & 0 deletions src/libyt_python_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ CodeValidity LibytPythonShell::check_code_validity(const std::string& code, bool

CodeValidity code_validity;

// clear error buffer before redirecting stderr
PyErr_Clear();
PyRun_SimpleString("import sys, io\n");
PyRun_SimpleString("sys.OUTPUT_STDERR=''\nstderr_buf=io.StringIO()\nsys.stderr=stderr_buf\n");

Expand Down Expand Up @@ -561,6 +563,7 @@ std::array<AccumulatedOutputString, 2> LibytPythonShell::execute_cell(const std:
#endif

// Clear the template buffer and redirect stdout, stderr
PyErr_Clear();
PyRun_SimpleString("import sys, io\n");
PyRun_SimpleString("sys.OUTPUT_STDOUT=''\nstdout_buf=io.StringIO()\nsys.stdout=stdout_buf\n");
PyRun_SimpleString("sys.OUTPUT_STDERR=''\nstderr_buf=io.StringIO()\nsys.stderr=stderr_buf\n");
Expand Down
Loading