Skip to content

Commit

Permalink
Got it to work, until it segfaults somewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 18, 2023
1 parent 92cb27c commit 05e1b47
Show file tree
Hide file tree
Showing 5 changed files with 454 additions and 39 deletions.
1 change: 1 addition & 0 deletions cpp/bmi_grpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ void run_bmi_server(BmiClass *model, int argc, char *argv[])
grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
grpc::ServerBuilder builder;
// builder.SetResourceQuota(grpc::ResourceQuota().SetMaxThreads(2));
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
Expand Down
8 changes: 4 additions & 4 deletions test/heat-images/c-julia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
cmake_minimum_required(VERSION 3.0)
project(run_bmi_server C CXX)
project(run_bmi_server CXX)

set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

set(_cflags "-ansi -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -O2")
find_package(PkgConfig REQUIRED)
pkg_check_modules(BMIC REQUIRED IMPORTED_TARGET bmic)
message("-- bmic include - ${BMIC_INCLUDE_DIRS}")
include_directories(${BMIC_INCLUDE_DIRS})
pkg_check_modules(BMICXX REQUIRED IMPORTED_TARGET bmicxx)
message("-- bmicxx include - ${BMICXX_INCLUDE_DIRS}")
include_directories(${BMICXX_INCLUDE_DIRS})
pkg_check_modules(GRPC4BMI REQUIRED grpc4bmi)

# See https://github.com/barche/embedding-julia
Expand Down
28 changes: 18 additions & 10 deletions test/heat-images/c-julia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# docker build -t heat:c-julia -f test/heat-images/c-julia/Dockerfile .
#
# docker run -ti --rm -p 55555:55555 heat:c-julia
#
# Run with
#
# ipython
Expand Down Expand Up @@ -45,9 +47,11 @@ RUN cmake .. && make install

# Install grpc4bmi, use commit c5cc9b9bf33b6043e8db242a07c6fb92b9c63f66
# head of bmi2 branch, PR https://github.com/eWaterCycle/grpc4bmi/pull/124
ARG GRPC4BMI_VERSION=c5cc9b9bf33b6043e8db242a07c6fb92b9c63f66
RUN git clone https://github.com/eWaterCycle/grpc4bmi /opt/grpc4bmi \
&& cd /opt/grpc4bmi && git checkout ${GRPC4BMI_VERSION}
# ARG GRPC4BMI_VERSION=c5cc9b9bf33b6043e8db242a07c6fb92b9c63f66
# RUN git clone https://github.com/eWaterCycle/grpc4bmi /opt/grpc4bmi \
# && cd /opt/grpc4bmi && git checkout ${GRPC4BMI_VERSION}
COPY cpp /opt/grpc4bmi/cpp
COPY proto /opt/grpc4bmi/proto
WORKDIR /opt/grpc4bmi/cpp/build
RUN cmake .. && make install

Expand All @@ -59,6 +63,14 @@ COPY test/heat-images/c-julia/run_bmi_server.cc /opt/grpc4bmiheatc-julia
COPY test/heat-images/c-julia/CMakeLists.txt /opt/grpc4bmiheatc-julia
RUN cmake .. && make install

FROM julia:bullseye AS jldeps

# Install heat-julia
RUN julia -e 'using Pkg; Pkg.add(url="https://github.com/csdms/bmi-example-julia.git",rev="80c34b4f2217599e600fe9372b1bae50e1229edf")' && \
julia -e 'using Pkg; Pkg.add("BasicModelInterface")'

RUN curl -L https://github.com/csdms/bmi-example-julia/raw/main/example/heat.toml > /usr/local/share/heat.toml

# run container
FROM julia:bullseye

Expand All @@ -68,15 +80,11 @@ RUN apt-get update && apt-get install -qy libssl1.1 && rm -rf /var/lib/apt/lists
# Copy compiled and deps
COPY --from=builder /usr/local/bin/run_bmi_server /usr/local/bin/run_bmi_server
COPY --from=builder /usr/local/lib/ /usr/local/lib/

# Install heat-julia
RUN julia -e 'using Pkg; Pkg.add(url="https://github.com/csdms/bmi-example-julia.git",rev="80c34b4f2217599e600fe9372b1bae50e1229edf")' && \
julia -e 'using Pkg; Pkg.add("BasicModelInterface")'

RUN curl -L https://github.com/csdms/bmi-example-julia/raw/main/example/heat.toml > /usr/local/share/heat.toml
COPY --from=jldeps /root/.julia/ /root/.julia/
COPY --from=jldeps /usr/local/share/heat.toml /usr/local/share/heat.toml

RUN echo '/usr/local/julia/lib' > /etc/ld.so.conf.d/julia.conf && ldconfig

ENV BMI_PORT=50051
# TODO run server as non-root user

ENTRYPOINT ["/usr/local/bin/run_bmi_server"]
175 changes: 175 additions & 0 deletions test/heat-images/c-julia/demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import grpc\n",
"from grpc4bmi.bmi_grpc_client import BmiClient\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"mymodel = BmiClient(grpc.insecure_channel(\"localhost:55555\"))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mymodel.initialize(\"/usr/local/share/heat.toml\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'The 2D Heat Equation'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mymodel.get_component_name()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "_InactiveRpcError",
"evalue": "<_InactiveRpcError of RPC that terminated with:\n\tstatus = StatusCode.UNAVAILABLE\n\tdetails = \"Socket closed\"\n\tdebug_error_string = \"UNKNOWN:Error received from peer ipv4:127.0.0.1:55555 {grpc_message:\"Socket closed\", grpc_status:14, created_time:\"2023-10-18T11:32:54.922549729+02:00\"}\"\n>",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31m_InactiveRpcError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb Cell 5\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb#W4sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m mymodel\u001b[39m.\u001b[39;49mget_component_name()\n",
"File \u001b[0;32m~/git/eWaterCycle/grpc4bmi/grpc4bmi/bmi_grpc_client.py:125\u001b[0m, in \u001b[0;36mBmiClient.get_component_name\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstub\u001b[39m.\u001b[39mgetComponentName(bmi_pb2\u001b[39m.\u001b[39mEmpty())\u001b[39m.\u001b[39mname)\n\u001b[1;32m 124\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mRpcError \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m--> 125\u001b[0m handle_error(e)\n",
"File \u001b[0;32m~/git/eWaterCycle/grpc4bmi/grpc4bmi/bmi_grpc_client.py:123\u001b[0m, in \u001b[0;36mBmiClient.get_component_name\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mget_component_name\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 122\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 123\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mstub\u001b[39m.\u001b[39;49mgetComponentName(bmi_pb2\u001b[39m.\u001b[39;49mEmpty())\u001b[39m.\u001b[39mname)\n\u001b[1;32m 124\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mRpcError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 125\u001b[0m handle_error(e)\n",
"File \u001b[0;32m~/git/eWaterCycle/grpc4bmi/.venv/lib/python3.10/site-packages/grpc/_channel.py:946\u001b[0m, in \u001b[0;36m_UnaryUnaryMultiCallable.__call__\u001b[0;34m(self, request, timeout, metadata, credentials, wait_for_ready, compression)\u001b[0m\n\u001b[1;32m 937\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m,\n\u001b[1;32m 938\u001b[0m request,\n\u001b[1;32m 939\u001b[0m timeout\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 942\u001b[0m wait_for_ready\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m,\n\u001b[1;32m 943\u001b[0m compression\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m):\n\u001b[1;32m 944\u001b[0m state, call, \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_blocking(request, timeout, metadata, credentials,\n\u001b[1;32m 945\u001b[0m wait_for_ready, compression)\n\u001b[0;32m--> 946\u001b[0m \u001b[39mreturn\u001b[39;00m _end_unary_response_blocking(state, call, \u001b[39mFalse\u001b[39;49;00m, \u001b[39mNone\u001b[39;49;00m)\n",
"File \u001b[0;32m~/git/eWaterCycle/grpc4bmi/.venv/lib/python3.10/site-packages/grpc/_channel.py:849\u001b[0m, in \u001b[0;36m_end_unary_response_blocking\u001b[0;34m(state, call, with_call, deadline)\u001b[0m\n\u001b[1;32m 847\u001b[0m \u001b[39mreturn\u001b[39;00m state\u001b[39m.\u001b[39mresponse\n\u001b[1;32m 848\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 849\u001b[0m \u001b[39mraise\u001b[39;00m _InactiveRpcError(state)\n",
"\u001b[0;31m_InactiveRpcError\u001b[0m: <_InactiveRpcError of RPC that terminated with:\n\tstatus = StatusCode.UNAVAILABLE\n\tdetails = \"Socket closed\"\n\tdebug_error_string = \"UNKNOWN:Error received from peer ipv4:127.0.0.1:55555 {grpc_message:\"Socket closed\", grpc_status:14, created_time:\"2023-10-18T11:32:54.922549729+02:00\"}\"\n>"
]
}
],
"source": [
"mymodel.get_component_name()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'The 2D Heat Equation'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mymodel.get_component_name()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from time import sleep"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
".\r"
]
},
{
"ename": "AttributeError",
"evalue": "module 'os' has no attribute 'sleep'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb Cell 8\u001b[0m line \u001b[0;36m3\n\u001b[1;32m <a href='vscode-notebook-cell:/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb#W6sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mfor\u001b[39;00m _ \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m100\u001b[39m):\n\u001b[1;32m <a href='vscode-notebook-cell:/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb#W6sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39m.\u001b[39m\u001b[39m'\u001b[39m, end\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m\\r\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb#W6sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m os\u001b[39m.\u001b[39;49msleep(\u001b[39m0.01\u001b[39m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/verhoes/git/eWaterCycle/grpc4bmi/test/heat-images/c-julia/demo.ipynb#W6sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m mymodel\u001b[39m.\u001b[39mget_component_name()\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'os' has no attribute 'sleep'"
]
}
],
"source": [
"for _ in range(100):\n",
" print('.', end='\\r')\n",
" sleep(0.01)\n",
" mymodel.get_component_name()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 05e1b47

Please sign in to comment.