Solved

RemotingException when running the BatchRayTrace with Python in Interactive Extension

  • 23 April 2021
  • 9 replies
  • 191 views

Userlevel 7
Badge +2

Dear Zemax Community,


When I try to use the BatchRayTrace tool from Python in an Interactive Extension, I get a RemotingException, which seem to be related to the use of the AddRay method in the IRayTraceNormUnpolData interface.


To reproduce the issue, try making Example 23 into an Interactive Extension (instead of a Standalone Application). Alternatively, this is my code snippet for an Interactive Extension:



from System import Enum, Int32, Double
# Open the BatchRayTrace tool
MyBatchRT = TheSystem.Tools.OpenBatchRayTrace()
# Add an unpolarized-raytrace
ToImageSurface = 3
MaxRays = 1
MyUnpolRT = MyBatchRT.CreateNormUnpol(MaxRays, ZOSAPI.Tools.RayTrace.RaysType.Real, ToImageSurface)
WaveNumber = Int32(0)
Hx = Double(0)
Hy = Double(0)
Px = Double(0)
Py = Double(0)
MyUnpolRT.AddRay(WaveNumber, Hx, Hy, Px, Py, Enum.Parse(ZOSAPI.Tools.RayTrace.OPDMode, 'None'))
# Run the raytrace
MyBatchRT.RunAndWaitForCompletion()
# Close the BatchRayTrace tool
MyBatchRT.Close()

Let me know if you have the same problem, and if you've found a solution to this, or if I'm missing something.


Thanks for your help, and take care,


David

icon

Best answer by Sandrine Auriol 28 April 2021, 16:00

View original

9 replies

Userlevel 6
Badge +2

Hi David


How are you?

I tested your code on my side and it seems to work well. I opened the '\Zemax\Samples\Sequential\Objectives\Double Gauss 28 degree field.zmx' sample file. I connected the Interactive Extension and ran your snippet and it all seems ok. So not sure where it can come from.


Could you share the full error message? Thank you.


Sandrine

Userlevel 7
Badge +2

Hi Sandrine,


I'm good, and yourself?


Actually, I've just tried again, and it is indeed working fine. Fortunately, I still hard the whole error message:



RemotingException Traceback (most recent call last)
in
184 #! [e23s06_py]
185 # Run Batch Ray Trace
--> 186 raytrace.RunAndWaitForCompletion()
187 #! [e23s06_py]
188
RemotingException: This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.
Server stack trace:
at System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ZemaxUI.ZOSAPI.Tools.RayTraceBatchData.CallbackHelper.source_ToolStartedEvent(ISystemTool sender)
at ZemaxUI.ZOSAPI.Tools.SystemToolBase.Run()
at ZemaxUI.ZOSAPI.Tools.SystemToolBase.RunAndWaitForCompletion()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ZemaxUI.ZOSAPI.Tools.SystemToolBase.RunAndWaitForCompletion()

I have no clue what this error means, and why I don't have it anymore. Do you have any idea?


Thanks for your help, and take care,


David

Userlevel 6
Badge +2

Hi David


Yes all good thanks.

This message is a bit cryptic to me. Are OpticStudio and Python on the same computer? 

I have searched a bit and found this link where someone mentions having this error when passing arraylists filled strings instead of singles. 

Let me know and I'll ask one of our developers. Thank you.


Sandrine

Userlevel 7
Badge +2

Hi Sandrine,


They were on the same computer.


Don't worry, it did not happen again yet, and I can live with not understanding this error :D


Have a great day,


David

Userlevel 6
Badge +2

Ok let's leave it for now.


Have a good evening!


Sandrine

Dear all,

 

I’ sorry to re-open this issue. I get exactly the same error message and in contrast to the thread opener, that problem does not simply disappear if I run the code again.

I would like to tweak some parameters of the optical system manually and subsequently run an array raytrace for analysis, thus I would very much prefer to be able running the array raytrace in interactive mode.

I attached two sample python files. These are slight adaptations to the example file #22 from the ZOS-API help.
The “business code” (i.e. the code that should actually execute the array raytrace) is identical -- it’s only the rigging up that differs. The common code is marked with a comment in the source files. As a side note: the single ray trace works in interactive mode (using raytrace.SingleRayNormUnpol).


Zemax Version: 21.3

Python: Version: 3.9.7

pythonnet Version: 2.5.1

 

Output of error message (unfortunately partially in German but I’m not able to change that to English since the whole system already setup-up using English language settings)

(py39) C:\Users\xxxxxxxx\Test>python ZOS_Interactive_ArrayRaytrace.py Found OpticStudio at: c:\program files\zemax opticstudio
Connected to OpticStudio
Serial #:  xxxxxxxxxx
<ZemaxUI.ZOSAPI.Tools.BatchRayTraceTool object at 0x000001A02A206130>

Traceback (most recent call last):   File "C:\Users\xxxxxxxx\Test\ZOS_Interactive_ArrayRaytrace.py", line 181, in <module>     raytrace.RunAndWaitForCompletion() System.Runtime.Remoting.RemotingException: Der Remoteproxy hat keine Channelsenke, d. h., der Server besitzt keine registrierten Serverchannel oder die Anwendung hat keinen passenden Clientchannel, um mit dem Server zu kommunizieren.

Server stack trace:    bei System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)    bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    bei ZemaxUI.ZOSAPI.Tools.RayTraceBatchData.CallbackHelper.source_ToolStartedEvent(ISystemTool sender)    bei ZemaxUI.ZOSAPI.Tools.SystemToolBase.Run()    bei ZemaxUI.ZOSAPI.Tools.SystemToolBase.RunAndWaitForCompletion()    bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)    bei System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at ZemaxUI.ZOSAPI.Tools.SystemToolBase.RunAndWaitForCompletion()

 

Any suggestions?

 

Cheers,

Peter

Userlevel 6
Badge +2

Hi Peter,

I have downloaded the code you sent but I do not see the same error. I will ask our developers if they recognize this. In the meantime, I have a few suggestions:

  1. Try restarting the computer completely. This error seems to be related to an issue with finding a “port” for the connection between the API and OpticStudio. Maybe refreshing your machine and making sure there are no other programs running will help
    • On that note, please ensure that you are not using all of your OpticStudio instances before running the Standalone Application. The standalone mode counts as one instance of OpticStudio so you will see an error if you’re already at your max. Additionally, please ensure you are using the Interactive Extension dialog box when running the interactive version of your code. 
  2. Try running sample #14 - the Sequential tolerance one. This sample also includes a RunAndWaitForCompletion() command and I’m curious to see if you get the same error for a different tool. 
  3. Potentially, you can try downgrading to Python 3.8. That is the version of Python the Zemax team uses (for the most part) and has been tested against most of the sample files

I’ll post here again when I hear back from the developers. Until then, let me know if anything changes!

Hi Allie,

thank you for your reply.

Downgrading to Python3.8 is not really an option, since I use language features elsewhere that require Python3.9.

The observed behaviour also made it unlikely that is has anything to do with the Python version, and indeed after installing the minor upgrade (from 21.3 to 21.3.1) that problem disappeared -- without changing anything in the code or python installation/environment.

 

For future readers:

If zosapi does not work for you in “interactive mode”. Upgrading to the next (minor) release may solve the problem (or consider downgrading to 21.3.1).

Interactive and standalone mode are known to work for:

  • python 3.9
  • pythonnet 2.5.1
  • Zemax 21.3.1 (not 21.3.0)

Peter

Userlevel 6
Badge +2

Hi Peter,

Thanks for the update!

I actually just heard back from the developers. They mentioned that a RemotingException typically means that the OpticStudio process has crashed. In other words, something in OpticStudio failed and the connection between it an Python was terminated. If you were seeing this frequently but it has now stopped, it could have been a problem with a DLL or component piece of the software which was updated upon your re-install of the program. All in all, I’m happy you can continue to move forward. 

PS - It’s also good to hear that Python 3.9 is working for you. I will update our KBA to acknowledge that!

Reply