Package: aliro-quantum-networking
aliro-aqnThis is an api for the Aliro Q.NetworkThis Python package is automatically generated by theOpenAPI Generatorproject:API version: 1.50.0Package version: 1.50.0Build package: org.openapitools.codegen.languages.PythonClientCodegenRequirements.Python 2.7 and 3.4+Installation & Usagepip installIf the python package is hosted on a repository, you can install directly using:pipinstallaliro-quantum-networkingThen import the package:importaliro_quantum_networkingGetting Started## Import necessary modulesimportaliro_quantum_networkingfromcontextlibimportcontextmanagerfromaliro_quantum_networking.modelsimportClassicalChannel,MemoryInput,Node,QuantumConnection,\Request,SubmissionAqnInput,SubmissionAqnOutput,SubmissionAqnBaseGlobalSettings,SubmissionOverviewInputfromaliro_quantum_networking.restimportApiExceptionfrompprintimportpprintfrommatplotlibimportpyplotaspltfromtypingimportContextManagerimportuuid## Set up authentication# You can retrieve your API token in your "Account" page at https://aqn.aliro.io/#/userconfiguration=aliro_quantum_networking.Configuration()configuration.api_key['Authorization']='API_TOKEN'configuration.host='https://aqn.aliro.io/v1'## Define nodes# Define the nodes in your topology.## In this example, there will be a linear topology, having two end nodes with 25 quantum memories and 1 repeater between them with 50 quantum memories.default_coherence_time=10# secondsdefault_raw_fidelity=0.85memory_request_size=5defnew_node_memory()->MemoryInput:returnMemoryInput(coherence_time=default_coherence_time,memory_type='MemoryInput',raw_fidelity=default_raw_fidelity)end_node_1=Node(name='alice',memories=[new_node_memory()foriinrange(memory_request_size)])end_node_2=Node(name='bob',memories=[new_node_memory()foriinrange(memory_request_size)])repeater_1=Node(name='repeater1',memories=[new_node_memory()foriinrange(memory_request_size*2)])submission_nodes=[end_node_1,repeater_1,end_node_2]## Define quantum connections# Define the quantum connections between nodes in your topology.## In this example, there will be two quantum connections, one between the repeater and each of the end nodes.default_quantum_connection_attenuation=1e-5# decibels/kilometerdefault_quantum_channel_distance=5e3# metersquantum_connections=[QuantumConnection(attenuation=default_quantum_connection_attenuation,distance=default_quantum_channel_distance,node_from=submission_nodes[0].name,node_to=submission_nodes[1].name),QuantumConnection(attenuation=default_quantum_connection_attenuation,distance=default_quantum_channel_distance,node_from=submission_nodes[1].name,node_to=submission_nodes[2].name)]## Define classical channels# Define the classical channels between nodes in the topology.## In this example, there will be an all-to-all classical connection topology.default_classical_channel_delay=25e7# picosecondsdefault_classical_channel_distance=1e3# meterssubmission_classical_channels=[]foriinsubmission_nodes:forjinsubmission_nodes:ifi.name!=j.name:submission_classical_channels.append(ClassicalChannel(delay=default_classical_channel_delay,distance=default_classical_channel_distance,node_from=i.name,node_to=j.name))## Define the desired network request# Define the desired network request to simulatedefault_request_target_fidelity=0.9default_request_simulation_start_time=1e12default_request_simulation_end_time=1e14network_request=Request(memory_size=memory_request_size,node_from=submission_nodes[0].name,node_to=submission_nodes[2].name,target_fidelity=default_request_target_fidelity,time_beginning=default_request_simulation_start_time,time_end=default_request_simulation_end_time)## Define full submission API input# Put all inputs into the full input to send to the Aliro APIsubmission_name=f'SubmissionTest_{uuid.uuid4().hex}'submission_input=SubmissionAqnInput(classical_channels=submission_classical_channels,global_settings=SubmissionAqnBaseGlobalSettings(excitation_rate=80000000,purification_protocol_name='BBPSSW_X'),nodes=submission_nodes,quantum_connections=quantum_connections,request=network_request,submission_overview=SubmissionOverviewInput(name=submission_name,runs=1,timeout=10,timeline_stop_time=3e12,submission_overview_type='SubmissionOverviewInput'))## Define submissions API instance context# This will set up our API client and catch errors.# This will be the same for all of our calls in this example, so we can define a reusable context here.@contextmanagerdefsubmissions_api_client(api_method_name:str)->ContextManager[aliro_quantum_networking.SubmissionsApi]:withaliro_quantum_networking.ApiClient(configuration)asapi_client:submissions_api_instance=aliro_quantum_networking.SubmissionsApi(api_client)try:yieldsubmissions_api_instanceexceptApiExceptionase:print(f"Exception when calling SubmissionsApi->{api_method_name}:{e}\n")## Submit the new submissionsubmission_id:strwithsubmissions_api_client(api_method_name='submissions_post')assubmissions_api_instance:submission_api_response=submissions_api_instance.submissions_post(submission_aqn_input=submission_input)pprint(submission_api_response)submission_id=submission_api_response.submission_id## Wait for completion# This will likely take a few minutes or more.submission_details:SubmissionAqnOutputwithsubmissions_api_client(api_method_name='submissions_details_stream_get')assubmissions_api_instance:forsubmission_get_responseinsubmissions_api_instance.submissions_details_stream_get(submission_id=submission_id):submission_details=submission_get_responsesubmission_is_complete=submission_details.submission_overview.complete_dateifsubmission_is_complete:break## Display number of entangled memoriesPICOSECONDS_PER_SECOND=1e12fig,axes=plt.subplots(1,3)axes[0].set_ylabel("Number of Entangled Memories")axes[1].set_xlabel("Simulation Time (s)")first_run_results=submission_details.run_results[0]node_names=[submission_node.nameforsubmission_nodeinsubmission_nodes]result_memories_all_nodes=[first_run_results.nodes[node_name].memoriesfornode_nameinnode_names]fornode_name,node_result_memories,axisinzip(node_names,result_memories_all_nodes,axes):data=sorted(info.entangled_at_time/PICOSECONDS_PER_SECONDforinfoinnode_result_memoriesifinfo.entangled_at_time)axis.set_title(node_name)axis.plot(data,range(1,len(data)+1),marker="o")fig.tight_layout()## Display fidelities for entangled memoriesfig,axes=plt.subplots(1,3)axes[0].set_ylabel("Fidelity")axes[1].set_xlabel("Memory Number")defset_ax_properties(axis,data):data_length=len(data)axis.bar(range(data_length),data)forfidelityin(default_raw_fidelity,0.9):axis.plot([0,data_length],2*[fidelity],"k--")axis.set_ylim(0.7,1)fornode_name,node_result_memories,axisinzip(node_names,result_memories_all_nodes,axes):data=[info.fidelityforinfoinnode_result_memories]axis.set_title(node_name)set_ax_properties(axis,data)fig.tight_layout()Documentation for API EndpointsAll URIs are relative tohttp://localhost:3998/v1ClassMethodHTTP requestDescriptionAuthenticationApiauth_login_postPOST/auth/loginlogin using username and passwordSubmissionsApisubmissions_details_stream_getGET/submissions/details/streamget details about a submission's resultsSubmissionsApisubmissions_postPOST/submissionssubmit a new submissionUserApiuser_api_key_postPOST/user/apiKeygenerate Aliro API key for userUserApiuser_information_update_postPOST/user/informationUpdateupdate user email and nameUserApiuser_password_change_postPOST/user/passwordChangechange user password from known passwordDocumentation For ModelsApiKeyApiKeyResponseBasicSuccessChangePasswordParametersClassicalChannelCredentialsBasicLoginResponseMemoryMemoryBaseMemoryInputMemoryOutputMemoryOutputAllOfNodeQuantumConnectionRequestSubmissionAqnSubmissionAqnBaseSubmissionAqnInputSubmissionAqnOutputSubmissionAqnOutputAllOfUpdateUserInformationParametersUserInfoDocumentation For AuthorizationJwtKeyAuthType: API keyAPI key parameter name: AuthorizationLocation: HTTP headerAuthornick@aliroquantum.com