-
Notifications
You must be signed in to change notification settings - Fork 30
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
Mismatch between local and remote Microscope interface #107
Comments
Here is one more issue with the current mechanism: it fills |
While investigating the issue and looking for solution I realized that a similar code in |
Hi @Baharis, I like your idea of retrieving the available methods from an initialized object rater than the class itself. A function returning the available methods fits nicely as a part of the server class, which is the case for the camera. External implementations like the one in instamatic Tecnai server would not benefit from the implementation being in the base class, as they would not (necessarily) inherit from that. Maybe there should be some core instamatic package, which contains the abstract microscope- and camera-interface and the MicroscopeController, and things like the GUI and experiments can be seperate packages. I don't have much experience of programming this kind of server communication. It feels a little strange to override |
The reason for trying to grab it from the class directly is especially to not have to initialize an object on a PC. This can be a limitation if you are running the client on a PC that is not connected to the microscope / camera. So this needs to be kept in mind. Btw, this whole server / client thing is a complete hack on my side, and I think using some rpc solution would be better these days, for example: https://docs.python.org/3/library/xmlrpc.html or whatever library is popular these days. |
Thank you so much for your thoughts! For the time being in PR #108 I removed the explicit check via |
Closed by #108 |
I recently started working with Instamatic and found an issue with the code structure that appeared after PR #99 . While I wholeheartedly agree with the overall philosophy behind the change – great props to @viljarjf – it confused me somewhat and led to some rather unexpected traceback and hours of confusion.
The problem
Imagine that you are working on a 2-computer configuration, where Instamatic GUI and camera server are run on Computer A, while microscope server is running on computer B. Following the instructions, you set up your installation, in particular your config files. On computer A, in
settings.yaml
you point towardsmicroscope/fei.yaml
, where you specifyinterface: fei
. With that, on initialization yourMicroscopeClient
will simulate a Microscope object that has exactly the same interface asFEIMicroscope
.Now on Computer B, you similarly create config files and specify
interface:fei
. Unfortunately, you quickly realize that theFEIMicroscope
class does not specify all methods for the method you want to run. For example,FEIMicroscope.stopStage
method is missing. But it's not a big deal, is it? Just quickly patch instopStage
on Computer B'sFEIMicroscope
, re-run the code and...What happens is particularly interesting: the server-side FEIMicroscope has the method available but since the
MicroscopeClient
is created based on a local declaration pulled usingget_microscope_class
, overloadedMicroscopeClient.__getattr__
does not know about – and thus does not call – the method, even though calling it viaMicroscopeClient._eval_dct
WOULD succeed.The application
The problem discussed above looks take in the vacuum; indeed, it seems that the solution requires one to simply pull the changes done to the
FEIMicroscope
from Computer B to Computer A and voila – problem solved. This is true in a typical scenario where both computers are similar and the amount and frequency of changes is not abnormal. However, if Computer B is particularly different from Computer A and B's FEIMicroscope utilizes libraries or other objects that are not available on A (think significantly different operating systems or proprietary software), sometimes it might be unfeasible or straight-up impossible to sync all the changes.In my particular case, I am trying to set up Instamatic on Windows XP using Instamatic Tecnai Server. Here, none of Computer A's current Microscope classes match the interface of B's TecnaiMicroscope – see an excerpt of the full table below:

The biggest consequence of this issue is that even though methods are properly implemented AND handled, they are not exposed by the
MicroscopeClient
, leading to some very confusing errors.The solution
I believe the current design of Instamatic is outstanding: a Server class can be written completely independently of the main program and, as long as it offers a matching interface, it can handle communication just fine, as proved by the Tecnai Server. Unfortunately, with the current design of MicroscopeClient updated in #99 , if I want to use this feature I need to do one of the following:
MicroscopeClient
interface is initialized, e.g. based onMicroscope().__dir__
list rather thanMicroscope.__dict__
— requires no other (i.e. regular) updates to main — according to my study would mess up wrapping ininstamatic/microscope/client.py
, line 90, but otherwise should work dynamically.The question
I think a patch suggested in point 3 shouldn't be particularly difficult and it should facilitate using Instamatic across machines. I will be happy to implement it but I might appreciate some help testing it on different setups. I want to ask specifically @viljarjf if you have other concerns regarding this approach. Have tried doing things this way before and failed due to a reason I did not notice? Or have you missed this issue because your Computer A and B have the same configuration?
Links to the files in question:
FEIMicroscope
classMicroscopeClient
classTecnaiMicroscope
classThe text was updated successfully, but these errors were encountered: