Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346<Chapter Label="ClientFunctionality">1<Heading>Client's functionality</Heading>23Sending and getting requests to the &SCSCP; server(s),4the client operates with processes. Process is an abstraction5which in other words may be also called a remote task. It encapsulates6an input/output TCP stream (see <Ref Filt="IsInputOutputTCPStream" />)7from the client to the server and the process ID of the CAS running8as a server (deduced from the connection initiation message; may be9unassigned, if the server CAS did not communicate it).10<P/>11There are two ways to create processes. One of them is to specify12the hostname and port where the &SCSCP; server is running; in this13case a new input/output TCP stream will be created. Another way is14first to establish the connection with the &SCSCP; server using15<Ref Func="NewSCSCPconnection" /> and then keep it alive across16multiple remote procedure calls, thus saving time on the DNS lookup17and connection initiation. This may give a good speedup in computations18with an intensive message exchange. Note that as long as such connection19is open, other &SCSCP; clients will not be able to get through, so20if several clients are interchanging with the &SCSCP; server at the21same time, they should not block each other with long-lasting connections.222324<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->2526<Section Label="SCSCP Connections">27<Heading>&SCSCP; connections</Heading>2829<#Include Label="IsSCSCPconnection"/>30<#Include Label="NewSCSCPconnection"/>31<#Include Label="CloseSCSCPconnection"/>3233</Section>343536<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->3738<Section Label="Client">39<Heading>Processes</Heading>4041<#Include Label="IsProcess"/>42<#Include Label="NewProcess"/>43<#Include Label="CompleteProcess"/>44<#Include Label="TerminateProcess"/>4546</Section>474849<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->5051<Section Label="All-in-one">52<Heading>All-in-one tool: sending request and getting result</Heading>5354<#Include Label="EvaluateBySCSCP"/>5556Now we demonstrate the procedure <C>GroupIdentificationService</C>,57also given in the previous chapter:5859<Example>60<![CDATA[61gap> G:=SymmetricGroup(4);62Sym( [ 1 .. 4 ] )63gap> gens:=GeneratorsOfGroup(G);64[ (1,2,3,4), (1,2) ]65gap> EvaluateBySCSCP( "GroupIdentificationService", [ gens ],66> "localhost", 26133 : debuglevel:=3 );67rec( attributes := [ [ "call_id", "localhost:26133:2442:xOilXtnw" ],68[ "info_runtime", 4 ], [ "info_memory", 2596114432 ],69[ "info_message", "Memory usage for the result is 48 bytes" ] ],70object := [ 24, 12 ] )71]]>72</Example>7374Service provider may suggest to the client to use a counterpart function7576<Example>77<![CDATA[78gap> IdGroupWS := function( G )79> local H, result;80> if not IsPermGroup(G) then81> H:= Image( IsomorphismPermGroup( G ) );82> else83> H := G;84> fi;85> result := EvaluateBySCSCP ( "GroupIdentificationService",86> [ GeneratorsOfGroup(H) ], "localhost", 26133 );87> return result.object;88> end;;89]]>90</Example>9192which works exactly like <Ref BookName="ref" Func="IdGroup" />:9394<Example>95<![CDATA[96gap> G:=DihedralGroup(64);97<pc group of size 64 with 6 generators>98gap> IdGroupWS(G);99[ 64, 52 ]100]]>101</Example>102103</Section>104105106<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->107108<Section Label="BinaryVsXML">109<Heading>Switching between Binary and XML &OpenMath; Encodings</Heading>110111<#Include Label="SwitchSCSCPmodeToBinary"/>112113For example, let us create a vector over <M>GF(3)</M>:114<Example>115<![CDATA[116gap> x := [ Z(3)^0, Z(3), 0*Z(3) ];117[ Z(3)^0, Z(3), 0*Z(3) ]118]]>119</Example>120The XML &OpenMath; encoding of such objects is quite bulky:121<Example>122<![CDATA[123gap> OMString( x );124"<OMOBJ xmlns=\"http://www.openmath.org/OpenMath\" version=\"2.0\"> <OMA> <OMS\125cd=\"list1\" name=\"list\"/> <OMA> <OMS cd=\"arith1\" name=\"power\"/> <OMA> \126<OMS cd=\"finfield1\" name=\"primitive_element\"/> <OMI>3</OMI> </OMA> <OMI>0<\127/OMI> </OMA> <OMA> <OMS cd=\"arith1\" name=\"power\"/> <OMA> <OMS cd=\"finfiel\128d1\" name=\"primitive_element\"/> <OMI>3</OMI> </OMA> <OMI>1</OMI> </OMA> <OMA\129> <OMS cd=\"arith1\" name=\"times\"/> <OMA> <OMS cd=\"finfield1\" name=\"primi\130tive_element\"/> <OMI>3</OMI> </OMA> <OMI>0</OMI> </OMA> </OMA> </OMOBJ>"131gap> Length( OMString(x) );132507133]]>134</Example>135We call the &SCSCP; procedure <C>Identity</C> just to test how this object136may be sent back and forth. The total length of the procedure call message137is 969 symbols:138<Log>139<![CDATA[140gap> SetInfoLevel(InfoSCSCP,3);141gap> EvaluateBySCSCP("Identity",[x],"localhost",26133);142#I Creating a socket ...143#I Connecting to a remote socket via TCP/IP ...144#I Got connection initiation message145#I <?scscp service_name="GAP" service_version="4.dev" service_id="localhost:2\1466133:42448" scscp_versions="1.0 1.1 1.2 1.3" ?>147#I Requesting version 1.3 from the server ...148#I Server confirmed version 1.3 to the client ...149#I Composing procedure_call message:150<?scscp start ?>151<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">152<OMATTR>153<OMATP>154<OMS cd="scscp1" name="call_id"/>155<OMSTR>localhost:26133:42448:IOs9ZkBU</OMSTR>156<OMS cd="scscp1" name="option_return_object"/>157<OMSTR></OMSTR>158</OMATP>159<OMA>160<OMS cd="scscp1" name="procedure_call"/>161<OMA>162<OMS cd="scscp_transient_1" name="Identity"/>163<OMA>164<OMS cd="list1" name="list"/>165<OMA>166<OMS cd="arith1" name="power"/>167<OMA>168<OMS cd="finfield1" name="primitive_element"/>169<OMI>3</OMI>170</OMA>171<OMI>0</OMI>172</OMA>173<OMA>174<OMS cd="arith1" name="power"/>175<OMA>176<OMS cd="finfield1" name="primitive_element"/>177<OMI>3</OMI>178</OMA>179<OMI>1</OMI>180</OMA>181<OMA>182<OMS cd="arith1" name="times"/>183<OMA>184<OMS cd="finfield1" name="primitive_element"/>185<OMI>3</OMI>186</OMA>187<OMI>0</OMI>188</OMA>189</OMA>190</OMA>191</OMA>192</OMATTR>193</OMOBJ>194<?scscp end ?>195#I Total length 969 characters196...197rec( attributes := [ [ "call_id", "localhost:26133:42448:IOs9ZkBU" ] ],198object := [ Z(3)^0, Z(3), 0*Z(3) ] )199]]>200</Log>201Now we switch to binary mode:202<Log>203<![CDATA[204gap> SwitchSCSCPmodeToBinary();205gap> EvaluateBySCSCP("Identity",[x],"localhost",26133);206#I Creating a socket ...207#I Connecting to a remote socket via TCP/IP ...208#I Got connection initiation message209#I <?scscp service_name="GAP" service_version="4.dev" service_id="localhost:2\2106133:42448" scscp_versions="1.0 1.1 1.2 1.3" ?>211#I Requesting version 1.3 from the server ...212#I Server confirmed version 1.3 to the client ...213#I Composing procedure_call message:2143C3F7363736370207374617274203F3E0A18121408060773637363703163616C6C5F6964061E6C\2156F63616C686F73743A32363133333A34323434383A3256675A5562755A0806147363736370316F\2167074696F6E5F72657475726E5F6F626A6563740600151008060E73637363703170726F63656475\21772655F63616C6C1008110873637363705F7472616E7369656E745F314964656E74697479100805\218046C697374316C69737410080605617269746831706F7765721008091166696E6669656C643170\21972696D69746976655F656C656D656E7401031101001110080605617269746831706F7765721008\220091166696E6669656C64317072696D69746976655F656C656D656E740103110101111008060561\221726974683174696D65731008091166696E6669656C64317072696D69746976655F656C656D656E\2227401031101001111111113193C3F736373637020656E64203F3E0A223#I Total length 339 bytes224#I Request sent ...225#I Waiting for reply ...226#I <?scscp start ?>227#I Got back: object [ Z(3)^0, Z(3), 0*Z(3) ] with attributes228[ [ "call_id", "localhost:26133:42448:2VgZUbuZ" ] ]229rec( attributes := [ [ "call_id", "localhost:26133:42448:2VgZUbuZ" ] ],230object := [ Z(3)^0, Z(3), 0*Z(3) ] )231gap> SetInfoLevel(InfoSCSCP,3);232]]>233</Log>234As we can see, the size of the message is almost three times shorter, and235this is not the limit. Switching to binary &OpenMath; encoding in236combination with pickling and unpickling from &IO; package (see in the last237Chapter) and special methods for pickling compressed vectors implemented238in the <Package>Cvec</Package> available in &GAP; 4.5 allow to239dramatically reduce the overhead for vectors and matrices over finite240fields, making a roundtrip up to a thousand times faster.241242</Section>243244245<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->246247<Section Label="Remote">248<Heading>Remote objects</Heading>249250The &SCSCP; package introduces new kind of objects - <E>remote objects</E>.251They provide an opportunity to manipulate with objects on remote services252without their actual transmitting over the network. Remote objects store253the information that allows to access the original object: the server name254and the port number through which the object can be accessed, and the variable255name under which it is stored in the remote system. Two remote objects are256equal if and only if all these three parameters coincide.257<P/>258259There are two types of remote object which differ by their lifetime:260<List>261<Item>temporary remote objects which exist only within a single session;</Item>262<Item>persistent remote objects which stay alive across multiple sessions.</Item>263</List>264265First we show the example of the temporary remote object in a session. The266procedure <C>PointImages</C> returns the set of images of a point <M>i</M>267under the generators of the group <M>G</M>. First we create the symmetric268group <M>S_3</M> on the client and store it remotely on the server269(call 1), then we compute set of images for <M>i=1,2</M> (calls 2,3) and270finally demonstrate that we may retrieve the group from the server (call 4):271272<Example>273<![CDATA[274gap> stream:=InputOutputTCPStream( "localhost", 26133 );275< input/output TCP stream to localhost:26133 >276gap> StartSCSCPsession(stream);277"localhost:26133:6184"278gap> OMPutProcedureCall( stream, "store_session",279> rec( object := [ SymmetricGroup(3) ],280> attributes := [ [ "call_id", "1" ],281> ["option_return_cookie"] ] ) );282true283gap> SCSCPwait( stream );284gap> G:=OMGetObjectWithAttributes( stream ).object;285< remote object scscp://localhost:26133/TEMPVarSCSCPo3Bc8J75 >286gap> OMPutProcedureCall( stream, "PointImages",287> rec( object := [ G, 1 ],288> attributes := [ [ "call_id", "2" ] ] ) );289true290gap> SCSCPwait( stream );291gap> OMGetObjectWithAttributes( stream );292rec( attributes := [ [ "call_id", "2" ] ], object := [ 2 ] )293gap> OMPutProcedureCall( stream, "PointImages",294> rec( object := [ G, 2 ],295> attributes := [ [ "call_id", "3" ] ] ) );296true297gap> SCSCPwait( stream );298gap> OMGetObjectWithAttributes( stream );299rec( attributes := [ [ "call_id", "3" ] ], object := [ 1, 3 ] )300gap> OMPutProcedureCall( stream, "retrieve",301> rec( object := [ G ],302> attributes := [ [ "call_id", "4" ] ] ) );303true304gap> SCSCPwait( stream );305gap> OMGetObjectWithAttributes( stream );306rec( attributes := [ [ "call_id", "4" ] ],307object := Group([ (1,2,3), (1,2) ]) )308gap> CloseStream(stream);309]]>310</Example>311312After the stream is closed, it is no longer possible to retrieve the313group <M>G</M> again or use it as an argument.314<P/>315316Thus, the usage of remote objects existing during a session reduces the317network traffic, since we pass only references instead of actual &OpenMath;318representation of an object. Also, the remote object on the server may319accumulate certain information in its properties and attributes, which may320not be included in it default &OpenMath; representation.321<P/>322323Now we show remote objects which remain alive after the session is324closed. Such remote objects may be accessed later, for example, by:325<List>326<Item>subsequent procedure calls from the same instance of &GAP; or another system;</Item>327<Item>other instances of &GAP; or another systems (if the identifier of an object is known)</Item>328<Item>another &SCSCP; servers which obtained a reference to such object as an argument of a procedure call.</Item>329</List>330331<#Include Label="StoreAsRemoteObject"/>332333Internally, the remote object carries all the information which is required334to get access to the original object: its identifier, server and port:335336<Example>337<![CDATA[338gap> s![1];339"TEMPVarSCSCPLvIUUtL3"340gap> s![2];341"localhost"342gap> s![3];34326133344]]>345</Example>346347When the remote object is printed in the &OpenMath; format, we348use symbols <C>@</C> and <C>:</C> to combine these parameters349in the &OpenMath; reference:350351<Example>352<![CDATA[353gap> OMPrint(s);354<OMOBJ>355<OMR href="scscp://localhost:26133/TEMPVarSCSCPLvIUUtL3" />356</OMOBJ>357]]>358</Example>359360This allows substitution of remote object as arguments into procedure calls361in the same manner like we do this with usual objects:362363<Example>364<![CDATA[365gap> EvaluateBySCSCP("WS_IdGroup",[s],"localhost",26133);366rec( attributes := [ [ "call_id", "localhost:26133:52918:Viq6EWBP" ] ],367Line 183 :368object := [ 6, 1 ] )369]]>370</Example>371372<#Include Label="IsRemoteObject"/>373<#Include Label="RemoteObjectsFamily"/>374<#Include Label="RetrieveRemoteObject"/>375<#Include Label="UnbindRemoteObject"/>376377Finally, we show an example when first we create a group on the service378running on port 26133, and then identify it on the service running on port37926134:380<Example>381<![CDATA[382gap> s:=StoreAsRemoteObject( SymmetricGroup(3), "localhost", 26133 );383< remote object scscp://localhost:26133/TEMPVarSCSCPNqc8Bkan >384gap> EvaluateBySCSCP( "WS_IdGroup", [ s ], "localhost", 26134 );385rec( object := [ 6, 1 ], attributes := [ [ "call_id", "localhost:26134:7414" ] ] )386]]>387</Example>388Instead of transmitting the group to the client and then sending it389as an argument to the second service, the latter service directly390retrieves the group from the first service:391<Example>392<![CDATA[393gap> EvaluateBySCSCP("WS_IdGroup",[s],"localhost",26133 : output:="cookie" );394rec( attributes := [ [ "call_id", "localhost:26133:52918:mRU6w471" ] ],395object := < remote object scscp://localhost:26133/TEMPVarSCSCPS9SVe9PZ > )396]]>397</Example>398399</Section>400401</Chapter>402403