open-simulation-platform / libcosim

OSP C++ co-simulation library
https://open-simulation-platform.github.io/libcosim
Mozilla Public License 2.0
61 stars 10 forks source link

Feature/proxy-fmu #633

Closed markaren closed 3 years ago

markaren commented 3 years ago

Adds proxy-fmu support to libcosim. proxy-fmu is implemented in C++ and supports automatic spawning of new processes. Thus it replaces the current usage of the JVM based fmu-proxy solution.

Closes #628

markaren commented 3 years ago

Integration works locally at this point.

markaren commented 3 years ago

Not finding FMILibrary on linux when building proxyfmu is such a weird error. conan create works when triggered from proxyfmu repository. Why does it fail here? I tried running plain conan install without going through conan create for libcosim first. Still the same error.

Note that the same error is reproduceable on a plain ubuntu installation.

@kyllingstad any ideas?

markaren commented 3 years ago

Some progress.. However, now I get:

/usr/bin/ld: /home/runner/.conan/data/proxyfmu/0.2.0/osp/testing/package/92604b6200473d2d3e7f23059f7748858bfa20eb/lib/libproxyfmu-client.a(remote_slave.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTVN8proxyfmu6thrift11BooleanReadE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
markaren commented 3 years ago

OK, now it builds, but I had to add PROPERTIES POSITION_INDEPENDENT_CODE ON to the proxyfmu libraries (fmi and client). Don't know the implications..

kyllingstad commented 3 years ago

Honestly, I don't know why they haven't made position-independent code the default in GCC yet. For most practical purposes, there are no negative implications, and PIC has the huge benefit that the code can later be linked into a into a dynamic library.

markaren commented 3 years ago

Might want to hold off reviewing until I got a proper test in place.

markaren commented 3 years ago

Mhh, as unittests are not run as part of the conan run, the proxyfmu test will never run in the CI.

ljamt commented 3 years ago

Looks like the conan CI fails. Is it related to thischange in proxy-fmu?

markaren commented 3 years ago

Doubt it. I ran with that update susessfully yesterday and here non proxy builds fails also.

markaren commented 3 years ago

cheduled maintenance is currently in progress. We will provide updates as necessary. Apr 22, 14:00 UTC - 18:00 UTC Scheduled - Detail: The DNS record http://conan.bintray.com will be routed to the new ConanCenter repository. Impact: Temporary instability, none lasting.

If you receive this error, it is related to this maintenance:

ljamt commented 3 years ago

Just build cosim-cli locally with the conan package from this branch: libcosim/0.8.0@osp/testing-feature_proxy-server

Then reconfigured the House demo configuration to the following:

    <Simulators>
        <Simulator name="Clock" source="proxyfmu://localhost?file=Clock.fmu"/>
        <Simulator name="InnerWall" source="proxyfmu://localhost?file=InnerWall.fmu"/>
        <Simulator name="OuterWall1" source="proxyfmu://localhost?file=OuterWall1.fmu">
            <InitialValues>
                <InitialValue variable="T_outside">
                    <Real value="5.3"/>
                </InitialValue>
            </InitialValues>
        </Simulator>
        <Simulator name="OuterWall2" source="proxyfmu://localhost?file=OuterWall2.fmu">
            <InitialValues>
                <InitialValue variable="T_outside">
                    <Real value="4.9"/>
                </InitialValue>
            </InitialValues>
        </Simulator>
        <Simulator name="Room1" source="proxyfmu://localhost?file=Room1.fmu"/>
        <Simulator name="Room2" source="proxyfmu://localhost?file=Room2.fmu"/>
        <Simulator name="TempController" source="proxyfmu://localhost?file=TempController.fmu"/>
    </Simulators>

Testing with cosim run c:\dev\cse-demos\house\OspSystemStructure_.xml -d 10

At first successful result:

@progress 1 1.000000 1.000000
@progress 2 2.000000 2.000000
@progress 3 3.000000 3.000000
@progress 4 4.000000 4.000000
@progress 5 5.000000 5.000000
@progress 6 6.000000 6.000000
@progress 7 7.000000 7.000000
@progress 8 8.000000 8.000000
@progress 9 9.000000 9.000000
@progress 10 10.000000 10.000000
[proxyfmu] Shutting down proxy for Clock::Clock done..
[proxyfmu] External proxy process for instance 'Clock' returned with status 0
[proxyfmu] Shutting down proxy for TempController::TempController done..
[proxyfmu] External proxy process for instance 'TempController' returned with status 0
[proxyfmu] Shutting down proxy for OuterWall1::OuterWall1 done..
[proxyfmu] External proxy process for instance 'OuterWall1' returned with status 0
[proxyfmu] Shutting down proxy for InnerWall::InnerWall done..
[proxyfmu] External proxy process for instance 'InnerWall' returned with status 0
[proxyfmu] Shutting down proxy for OuterWall2::OuterWall2 done..
[proxyfmu] External proxy process for instance 'OuterWall2' returned with status 0
[proxyfmu] Shutting down proxy for Room1::Room1 done..
[proxyfmu] External proxy process for instance 'Room1' returned with status 0
[proxyfmu] Shutting down proxy for Room2::Room2 done..
[proxyfmu] External proxy process for instance 'Room2' returned with status 0

But subsequent simulations gave:

Attempt 2:
Thrift: Thu May  6 16:42:20 2021 TServerSocket::listen() BIND 64466
Unhandled Exception reached the top of main: Could not bind: errno = 10013, application will now exit
[proxyfmu] External proxy process for instance 'Room1' returned with status 2
Thrift: Thu May  6 16:42:23 2021 TSocket::open() connect() <Host: localhost Port: 64466>: errno = 10061
Thrift: Thu May  6 16:42:25 2021 TSocket::open() connect() <Host: localhost Port: 64466>: errno = 10061

Attempt 3:
Thrift: Thu May  6 16:42:29 2021 TServerSocket::listen() BIND 53205
Unhandled Exception reached the top of main: Could not bind: errno = 10013, application will now exit
[proxyfmu] External proxy process for instance 'OuterWall1' returned with status 2
Thrift: Thu May  6 16:42:32 2021 TSocket::open() connect() <Host: localhost Port: 53205>: errno = 10061
Thrift: Thu May  6 16:42:34 2021 TSocket::open() connect() <Host: localhost Port: 53205>: errno = 10061

Attempt 4:
Thrift: Thu May  6 16:42:49 2021 TServerSocket::listen() BIND 53308
Unhandled Exception reached the top of main: Could not bind: errno = 10013, application will now exit
[proxyfmu] External proxy process for instance 'InnerWall' returned with status 2
Thrift: Thu May  6 16:42:52 2021 TSocket::open() connect() <Host: localhost Port: 53308>: errno = 10061
Thrift: Thu May  6 16:42:54 2021 TSocket::open() connect() <Host: localhost Port: 53308>: errno = 10061

Curious to hear if you see the same.

markaren commented 3 years ago

Hmm, runs fine here (same case). You might have been unlucky with the port selection?

ljamt commented 3 years ago

Hmm, runs fine here (same case). You might have been unlucky with the port selection?

You are probably right. For me, this specific case works ~3 out of 10 attempts.

markaren commented 3 years ago

Can merge this once a new release has been made from master and @ljamt has vetted it. I'd also like to have #637 merged first, so I can make use of it in this PR.

ljamt commented 3 years ago

Can merge this once a new release has been made from master and @ljamt has vetted it. I'd also like to have #637 merged first, so I can make use of it in this PR.

Done testing and approving the PR now. Great work!! Apologies for the delay.

markaren commented 3 years ago

There is still the issue that this feature is not part of the unit testing though...

ljamt commented 3 years ago

There is still the issue that this feature is not part of the unit testing though...

This PR includes two unit test files. What feature is not part of the unit testing?

markaren commented 3 years ago

Conan builds are not tested through the CI.

markaren commented 3 years ago

Enabled testing for this feature. Tests passes, but some other issues appeared for gcc8.