o
    xi?I                     @  s   d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z d dl	mZ d dlmZ d dlmZmZ d	d
lmZ edZG dd deejZdS )    )annotationsN)Anycast)override)wandb_internal_pb2)wandb_telemetry_pb2)MailboxHandle)json_dumps_saferjson_friendly   )InterfaceBasewandbc                      sp  e Zd ZdZd fddZejdddddZejdddZe	ddd ddZ
e	ddd!ddZd"ddZd#ddZd$d"d#Zd%d&d'Zd&d*d+Zd'd.d/Zd(d2d3Zd)d6d7Zd*d;d<Z	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=d+d,d{d|Z	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=	=d-d.ddZd/ddZd0d1ddZd2ddZdddZdddZd3ddZd4ddZd5ddZd6ddZd7ddĄZ d8ddǄZ!d9ddɄZ"d:dd̄Z#d;ddτZ$d<ddӄZ%d=ddքZ&d>ddلZ'd?dd܄Z(d@dd߄Z)dAddZ*dBddZ+dCddZ,dDddZ-dEddZ.dFddZ/dGddZ0dHddZ1dIddZ2dJddZ3dKd dZ4dLddZ5dMddZ6dNdd	Z7dOddZ8dPddZ9dQddZ:dRddZ;dSddZ<dTddZ=  Z>S (U  InterfaceSharedaJ  Partially implemented InterfaceBase.

    There is little reason for this to exist separately from InterfaceBase,
    which itself is not a pure abstract class and has no other direct
    subclasses. Most methods are implemented in this class in terms of the
    protected _publish and _deliver methods defined by subclasses.
    returnNonec                   s   t    d S )N)super__init__)self	__class__ X/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/interface/interface_shared.pyr      s   zInterfaceShared.__init__Fnowaitrecord	pb.Recordr   boolc                C     dS )a  Send a record to the internal service.

        Args:
            record: The record to send. This method assigns its stream ID.
            nowait: If true, this does not block on socket IO and is safe
                to call in W&B's asyncio thread, but it will also not slow
                down even if the socket is blocked and allow data to accumulate
                in the Python memory.
        Nr   )r   r   r   r   r   r   _publish       zInterfaceShared._publishMailboxHandle[pb.Result]c                 C  r   )zSend a record to the internal service and return a response handle.

        Args:
            record: The record to send. This method assigns its stream ID.

        Returns:
            A mailbox handle for waiting for a response.
        Nr   )r   r   r   r   r   _deliver0   r   zInterfaceShared._deliveroutdatapb.OutputRecordc                C  &   t  }|j| | j||d d S Nr   )pbRecordoutputCopyFromr   r   r"   r   recr   r   r   _publish_output;      zInterfaceShared._publish_outputpb.OutputRawRecordc                C  r$   r%   )r&   r'   
output_rawr)   r   r*   r   r   r   _publish_output_rawF   r-   z#InterfaceShared._publish_output_rawcancelpb.CancelRequestc                 C     | j |d}| | d S )N)r1   _make_requestr   )r   r1   r+   r   r   r   _publish_cancelQ      zInterfaceShared._publish_canceltbrecordpb.TBRecordc                 C  r3   )N)r8   _make_recordr   )r   r8   r+   r   r   r   _publish_tbdataU   r7   zInterfaceShared._publish_tbdatapartial_historypb.PartialHistoryRequestc                 C  r3   )N)r=   r4   )r   r=   r+   r   r   r   _publish_partial_historyY      z(InterfaceShared._publish_partial_historyhistorypb.HistoryRecordc                 C  r3   )N)rA   r:   )r   rA   r+   r   r   r   _publish_history_   r7   z InterfaceShared._publish_historypreempt_recpb.RunPreemptingRecordc                 C  r3   )N)
preemptingr:   )r   rD   r+   r   r   r   _publish_preemptingc   r7   z#InterfaceShared._publish_preemptingtelemtpb.TelemetryRecordc                 C  r3   )N)	telemetryr:   )r   rH   r+   r   r   r   _publish_telemetryg   r7   z"InterfaceShared._publish_telemetryenvironmentpb.EnvironmentRecordc                 C  r3   )N)rL   r:   )r   rL   r+   r   r   r   _publish_environmentk   r7   z$InterfaceShared._publish_environment	job_inputpb.JobInputRequestc                 C     | j |d}| |S )N)rO   r5   r!   )r   rO   r   r   r   r   _publish_job_inputo      
z"InterfaceShared._publish_job_input
stats_dictdictpb.StatsRecordc                 C  sV   t  }t jjj|_|j  | D ]\}}|j	 }||_
tt|d |_q|S )Nr   )r&   StatsRecord	StatsTypeSYSTEM
stats_type	timestampGetCurrentTimeitemsitemaddkeyr	   r
   
value_json)r   rU   statskvr_   r   r   r   _make_statsu   s   

zInterfaceShared._make_statsNget_summarypb.GetSummaryRequest | Nonepausepb.PauseRequest | Noneresumepb.ResumeRequest | Nonestatuspb.StatusRequest | Nonestop_statuspb.StopStatusRequest | Noneinternal_messages!pb.InternalMessagesRequest | Nonenetwork_statuspb.NetworkStatusRequest | None	poll_exitpb.PollExitRequest | Nonepb.PartialHistoryRequest | Nonesampled_historypb.SampledHistoryRequest | None	run_startpb.RunStartRequest | Nonecheck_versionpb.CheckVersionRequest | Nonelog_artifactpb.LogArtifactRequest | Nonedownload_artifact!pb.DownloadArtifactRequest | Nonelink_artifactpb.LinkArtifactRequest | Nonedeferpb.DeferRequest | Noneattachpb.AttachRequest | Noneserver_infopb.ServerInfoRequest | None	keepalivepb.KeepaliveRequest | None
run_statuspb.RunStatusRequest | Nonesender_markpb.SenderMarkRequest | Nonesender_readpb.SenderReadRequest | Nonesync_finishpb.SyncFinishRequest | Nonestatus_reportpb.StatusReportRequest | Nonepb.CancelRequest | Nonesummary_recordpb.SummaryRecordRequest | Nonetelemetry_record pb.TelemetryRecordRequest | Noneget_system_metrics!pb.GetSystemMetricsRequest | Nonepython_packagespb.PythonPackagesRequest | Nonepb.JobInputRequest | Nonerun_finish_without_exit%pb.RunFinishWithoutExitRequest | Noneprobe_system_info pb.ProbeSystemInfoRequest | Nonec!           #      C  s  t  }!|r|!j| n#|r|!j| n|r"|!j| n|r,|!j| n|r5|!j| n|r>|!j| n|rG|!j	| n|rP|!j
| n|	rY|!j|	 n|
rb|!j|
 n|rk|!j| n|rt|!j| n|r}|!j| n|r|!j| n|r|!j| n|r|!j| n|r|!j| n|r|!j| n|r|!j| n~|r|!j| nu|r|!j| nl|r|!j| nc|r|!j| nZ|r|!j| nQ|r|!j| nH|r|!j| n?|r|!j| n6|r|!j| n,|r|!j| n"|r|!j | n|r#|!j!| n| r-|!j"|  nt#d| j$|!d}"d|"j%_&|rBd|"j%_'|"S )NzInvalid requestrequestT)(r&   Requestrg   r)   ri   rk   rm   ro   rq   rs   ru   r=   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r1   r   r   r   r   r   r   rO   r   r   	Exceptionr;   controllocalflow_control)#r   rg   ri   rk   rm   ro   rq   rs   ru   r=   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r1   r   r   r   r   rO   r   r   r   r   r   r   r   r5      s   #zInterfaceShared._make_requestrunpb.RunRecord | Noneconfigpb.ConfigRecord | Nonefilespb.FilesRecord | Nonesummarypb.SummaryRecord | Nonepb.HistoryRecord | Nonerc   pb.StatsRecord | Noneexitpb.RunExitRecord | Noneartifactpb.ArtifactRecord | Nonepb.TBRecord | Nonealertpb.AlertRecord | Nonefinalpb.FinalRecord | Nonemetricpb.MetricRecord | Noneheaderpb.HeaderRecord | Nonefooterpb.FooterRecord | Noner   pb.Request | NonerJ   tpb.TelemetryRecord | NonerF   pb.RunPreemptingRecord | Noneuse_artifactpb.UseArtifactRecord | Noner(   pb.OutputRecord | Noner/   pb.OutputRawRecord | Nonepb.EnvironmentRecord | Nonec                 C  s  t  }|r|j| |S |r|j| |S |r"|j| |S |r,|j| |S |r6|j| |S |r@|j| |S |rJ|j	| |S |rT|j
| |S |	r^|j|	 |S |
rh|j|
 |S |rr|j| |S |r||j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S |r|j| |S td)NzInvalid record)r&   r'   r   r)   r   r   rA   r   rc   r   r   r8   r   r   r   r   r   rJ   r   rF   r   r(   r/   rL   r   )r   r   r   r   r   rA   rc   r   r   r8   r   r   r   r   r   r   rJ   rF   r   r(   r/   rL   r   r   r   r   r;      s   +)'%#!	zInterfaceShared._make_recordstatepb.DeferRequest.DeferState.Vc                 C  s.   t j|d}| j|d}d|j_| | d S )N)r   )r   T)r&   DeferRequestr5   r   r   r   )r   r   r   r+   r   r   r   _publish_defer3  s   zInterfaceShared._publish_deferr   intc                 C  s   |  td| d S )Nr   )r   r   )r   r   r   r   r   publish_defer9  s   zInterfaceShared.publish_deferpb.HeaderRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_header<  r7   zInterfaceShared._publish_headerc                 C  "   t  }| j|d}| | d S )N)r   )r&   FooterRecordr;   r   )r   r   r+   r   r   r   publish_footer@     zInterfaceShared.publish_footerc                 C  r   )N)r   )r&   FinalRecordr;   r   )r   r   r+   r   r   r   publish_finalE  r   zInterfaceShared.publish_finalpb.PauseRequestc                 C  r3   )N)ri   r4   )r   ri   r+   r   r   r   _publish_pauseJ  r7   zInterfaceShared._publish_pausepb.ResumeRequestc                 C  r3   )N)rk   r4   )r   rk   r+   r   r   r   _publish_resumeN  r7   zInterfaceShared._publish_resumepb.RunRecordc                 C  r3   N)r   r:   )r   r   r+   r   r   r   _publish_runR  r7   zInterfaceShared._publish_runcfgpb.ConfigRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_configV  r7   zInterfaceShared._publish_configpb.SummaryRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_summaryZ  r7   z InterfaceShared._publish_summarypb.MetricRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_metric^  r7   zInterfaceShared._publish_metricc                 C  s$   |  |}| j|d}| | d S )N)rc   )rf   r;   r   )r   rU   rc   r+   r   r   r   publish_statsb  s   
zInterfaceShared.publish_statspb.PythonPackagesRequestc                 C  r3   )N)r   r4   )r   r   r+   r   r   r   _publish_python_packagesg  r@   z(InterfaceShared._publish_python_packagespb.FilesRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_filesm  r7   zInterfaceShared._publish_filespb.UseArtifactRecordr   c                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_use_artifactq  r7   z%InterfaceShared._publish_use_artifactpb.ProbeSystemInfoRequestc                 C  r3   )N)r   r4   )r   r   r   r   r   r   _publish_probe_system_infou  r@   z*InterfaceShared._publish_probe_system_infopb.LogArtifactRequestc                 C  rQ   )N)r~   rR   )r   r~   r+   r   r   r   _deliver_artifact{     
z!InterfaceShared._deliver_artifactpb.DownloadArtifactRequestc                 C  rQ   )N)r   rR   )r   r   r+   r   r   r   _deliver_download_artifact  rT   z*InterfaceShared._deliver_download_artifactpb.LinkArtifactRequestc                 C  rQ   )N)r   rR   )r   r   r+   r   r   r   _deliver_link_artifact  rT   z&InterfaceShared._deliver_link_artifactproto_artifactpb.ArtifactRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_artifact  r7   z!InterfaceShared._publish_artifactproto_alertpb.AlertRecordc                 C  r3   )N)r   r:   )r   r   r+   r   r   r   _publish_alert  r7   zInterfaceShared._publish_alertpb.StatusRequestc                 C  rQ   )N)rm   rR   )r   rm   reqr   r   r   _deliver_status  r   zInterfaceShared._deliver_status	exit_datapb.RunExitRecordc                 C  r3   N)r   r:   )r   r  r+   r   r   r   _publish_exit  r7   zInterfaceShared._publish_exitpb.KeepaliveRequestc                 C  r3   )N)r   r4   )r   r   r   r   r   r   _publish_keepalive  r7   z"InterfaceShared._publish_keepalivec                 C  s&   t jt  d}| j|d}| |S )N)shutdownr   )r&   r   ShutdownRequestr;   r!   )r   r   r   r   r   r   _deliver_shutdown  s   
z!InterfaceShared._deliver_shutdownc                 C  rQ   r   r;   r!   )r   r   r   r   r   r   _deliver_run  s   
zInterfaceShared._deliver_runpb.SyncFinishRequestc                 C  rQ   )N)r   rR   )r   r   r   r   r   r   _deliver_finish_sync  r   z$InterfaceShared._deliver_finish_syncpb.RunStartRequestc                 C  rQ   )N)rz   rR   )r   rz   r   r   r   r   _deliver_run_start  r   z"InterfaceShared._deliver_run_startpb.GetSummaryRequestc                 C  rQ   )N)rg   rR   )r   rg   r   r   r   r   _deliver_get_summary  r   z$InterfaceShared._deliver_get_summarypb.GetSystemMetricsRequestc                 C  rQ   )N)r   rR   )r   r   r   r   r   r   _deliver_get_system_metrics  rT   z+InterfaceShared._deliver_get_system_metricsc                 C  rQ   r  r
  )r   r  r   r   r   r   _deliver_exit  r   zInterfaceShared._deliver_exitpb.PollExitRequestc                 C  rQ   )N)ru   rR   )r   ru   r   r   r   r   _deliver_poll_exit  r   z"InterfaceShared._deliver_poll_exitpb.RunFinishWithoutExitRequestc                 C  rQ   )N)r   rR   )r   r   r   r   r   r   _deliver_finish_without_exit  rT   z,InterfaceShared._deliver_finish_without_exitpb.StopStatusRequestc                 C  rQ   )N)ro   rR   )r   ro   r   r   r   r   _deliver_stop_status  r   z$InterfaceShared._deliver_stop_statuspb.AttachRequestc                 C  rQ   )N)r   rR   )r   r   r   r   r   r   _deliver_attach  r   zInterfaceShared._deliver_attachpb.NetworkStatusRequestc                 C  rQ   )N)rs   rR   )r   rs   r   r   r   r   _deliver_network_status  rT   z'InterfaceShared._deliver_network_statusinternal_messagepb.InternalMessagesRequestc                 C  rQ   )N)rq   rR   )r   r  r   r   r   r   _deliver_internal_messages  rT   z*InterfaceShared._deliver_internal_messagespb.SampledHistoryRequestc                 C  rQ   )N)rx   rR   )r   rx   r   r   r   r    _deliver_request_sampled_history  rT   z0InterfaceShared._deliver_request_sampled_historypb.RunStatusRequestc                 C  rQ   )N)r   rR   )r   r   r   r   r   r   _deliver_request_run_status  rT   z+InterfaceShared._deliver_request_run_status)r   r   )r   r   r   r   r   r   )r   r   r   r    )r"   r#   r   r   r   r   )r"   r.   r   r   r   r   )r1   r2   r   r   )r8   r9   r   r   )r=   r>   r   r   )rA   rB   r   r   )rD   rE   r   r   )rH   rI   r   r   )rL   rM   r   r   )rO   rP   r   r    )rU   rV   r   rW   ) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN)Brg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   r=   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r1   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   r   r   )NNNNNNNNNNNNNNNNNNNNN),r   r   r   r   r   r   r   r   rA   r   rc   r   r   r   r   r   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   rJ   r   rF   r   r   r   r(   r   r/   r   rL   r   r   r   )r   r   r   r   )r   )r   r   r   r   )r   r   r   r   )ri   r   r   r   )rk   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )rU   rV   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r~   r   r   r    )r   r   r   r    )r   r   r   r    )r   r   r   r   )r   r   r   r   )rm   r   r   r    )r  r  r   r   )r   r  r   r   )r   r    )r   r   r   r    )r   r  r   r    )rz   r  r   r    )rg   r  r   r    )r   r  r   r    )r  r  r   r    )ru   r  r   r    )r   r  r   r    )ro   r  r   r    )r   r  r   r    )rs   r  r   r    )r  r   r   r    )rx   r"  r   r    )r   r$  r   r    )?__name__
__module____qualname____doc__r   abcabstractmethodr   r!   r   r,   r0   r6   r<   r?   rC   rG   rK   rN   rS   rf   r5   r;   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  __classcell__r   r   r   r   r      s    


oGr   )
__future__r   r*  loggingtypingr   r   typing_extensionsr   wandb.protor   r&   r   tpbwandb.sdk.mailboxr   
wandb.utilr	   r
   	interfacer   	getLoggerloggerABCr   r   r   r   r   <module>   s    
