qat.qlmaas.QLMaaSConnection
- class qat.qlmaas.QLMaaSConnection(hostname: str = None, port: int = None, authentication: str = None, certificate: str = None, key: str = None, check_host: bool = None, timeout: int = None, **kwargs)
QLMaaSConnection must be used to connect to a QLMaaS server. This class provides tools to define plugins and QPUs on the server and to get informations of the submtted jobs
Note
Each argument of the constructor is optional. If one of the argument is not passed in argument, the value of this argument is taken from the QLMaaS configuration file
- Parameters:
hostname (str, optional) – Hostname of the server
port (int, optional) – port listened by the server Default: 443
authentication (str, optional) – Authentication method. The authentication is either
"password"to login using a pair username/password or"ssl"to login using a SSL certificate Default: Falsecertificate (str, optional) – path to SSL certificate
key (str, optional) – path to SSL key
check_host (bool, optional) – checks the certificate of the server Default: True
proxy_host (str, optional) – hostname of the HTTPS proxy (if you want to use an HTTPS proxy - using an HTTPS proxy is not compatible with SSL authentication)
proxy_port (int, optional) – port of the HTTPS proxy (if you want to use an HTTPS proxy - using an HTTPS proxy is not compatible with SSL authentication)
timeout (int, optional) – keep alive connection timeout
- change_password()
Interactive method for changing the current account password
>>> from qat.qlmaas import QLMaaSConnection >>> conn = QLMaaSConnection(...) >>> conn.change_password() # This function does not take any argument ... New password: ... Repeat new passord:
- create_config()
Saves the current connection parameters in a simple configuration file. Login-specific information is not written.
- delete_files(filenames: str | list)
Delete files stored on the server, using the list of filenames.
Warning
Only give the name of the file (
"file.txt") and not a path to the file ("usr/path/file.txt")from qlmaas.utils import delete_files # To delete only one file, you can use the str signature delete_files("file.py") # To delete multiple files, you need to use the list signature delete_files(["file.py", "test.txt"])
- Parameters:
filename (str | list[str]) – string or list of filenames to delete.
- download_files(filenames: str | list, local_dir: str = '.')
Download, from the server, the files given as argument.
Warning
Only give the name of the file (
"file.txt") and not a path to the file ("usr/path/file.txt")from qlmaas.utils import download_files # To download only one file, you can use the str signature download_files("file.py") # To download multiple files, you need to use the list signature download_files(["file.py", "test.txt"])
- Parameters:
filenames (str | list[str]) – string or list of filenames to download.
local_dir (str, optional) – path to the local destination directory. Defaults to
"."(i.e., current working directory)
- get_generator(name)
Returns a remote BatchGenerator. Its name is checked against the list of available generators.
from qat.qlmaas import QLMaaSConnection # Create connection conn = QLMaasConnection(...) # Get a remote generator MaxCutGenerator = conn.get_generator("qat.generators:MaxCutGenerator")
- Parameters:
name (str) – the generator name in the format
module:classname- Returns:
Remote generator
- Return type:
- get_generators()
Gets the list of Generators available on the server. These Generators are a list of identifiers
from qat.qlmaas import QLMaaSConnection conn = QLMaaSConnection() available_generators = conn.get_generators()
- Returns:
list of Generators available on the server
- Return type:
list<ServiceDescription>
- get_importable(name: str)
Gets an application or remote object from its identifier. An identifier is composed of a module name and an object name (format: ‘module:name’)
- Parameters:
name (str) – application/object identifer
- Returns:
remote application or remote object
- Return type:
QLMaaSBasicApplication or QLMaaSRemoteObject
- get_importables_in_module(module_name: str)
Get the list of applications/objects in a module available on the server side.
- Parameters:
module_name (str) – module name
- Returns:
list of Applications available on the server
- Return type:
list<ServiceDesription>
- get_job(job_id: str)
Returns an
AsyncResultusing its job id. AnAsyncResultis a high level class used to easily manipulate a job- Parameters:
job_id (str) – the job id
- Returns:
the pending result
- Return type:
- get_jobs_info(*args)
List all the jobs that have been submitted by the current user. Jobs having a status DELETED are not returned by this function.
This function returns also information on each job like:
the status
the submission date
the amount of resources reserved for the job
some meta data (useful if the job has failed)
from qat.qlmaas import QLMaaSConnection connection = QLMaaSConnection(...) connection.get_jobs_info()
To get information on a specific job, please refer to the the class
AsyncResult- Returns:
list of job information
- Return type:
list<
JobInfo>
- get_plugin(name)
Returns a remote Plugin. Its name is checked against the list of available plugins.
from qat.qlmaas import QLMaaSConnection # Create connection conn = QLMaasConnection(...) # Get a remote Plugin Nnizer = conn.get_plugin("qat.plugins:Nnizer")
- Parameters:
name (str) – the plugin name in the format
module:classname- Returns:
Remote plugin
- Return type:
- get_plugins()
Gets the list of Plugins available on the server. These Plugins are a list of identifiers
from qat.qlmaas import QLMaaSConnection conn = QLMaaSConnection() available_plugins = conn.get_plugins()
- Returns:
list of Plugins available on the server
- Return type:
list<ServiceDescription>
- get_qpu(name)
Returns a remote QPU. Its name is checked against the list of available qpus.
from qat.qlmaas import QLMaaSConnection # Create connection conn = QLMaasConnection(...) # Get a remote QPU LinAlg = conn.get_qpu("qat.qpus:LinAlg")
- Parameters:
name (str) – the qpu name in the format
module:classname- Returns:
remote QPU
- Return type:
- get_qpus()
Gets the list of QPUs available on the server. These QPUs are a list of identifiers
from qat.qlmaas import QLMaaSConnection conn = QLMaaSConnection() available_qpus = conn.get_qpus()
- Returns:
list of QPUs available on the server
- Return type:
list<ServiceDescription>
- list_files()
Retrieve the list of the files available on the server.
- Returns:
list of all filenames present on the server.
- Return type:
list[str]
- mirror_files(local_dir: str, direction: str, *, force: bool = False)
Synchronize files between a local directory and the remote server.
Depending on the specified direction, this function either uploads all files from the local directory to the server or downloads all files from the server to the local directory.
Warning
Beware, the
local_dircannot have folder in it.from qlmaas.utils import mirror_files # Upload in the remote server folder, # force=True will erase everything inside # the remote server folder before uploading the files. mirror_files("folder", "upload", force=True) # Download in the local folder, # force=False will check that no files are in the local folder # before downloading all files from the server side mirror_files("folder", "download", force=False)
- Parameters:
local_dir (str) – path to the local directory.
direction (str) –
direction of the synchronization:
"upload"(to create a copy of the local directory on the server)"download"(to create a local copy of the files stored on the server)
force (bool, optional) – if
True, erase every existing files on the destination side. Defaults toFalse.
- open_prompt()
Drops in a qlmaas interactive tool. Please refer to the section
promptto get more information on the prompt interactive tool
- save_certificate(certificate: str)
Save an SSL certificate as authentication parameter
Note
Calling this function will udpate the certificate linked to your profile on the server side. Logging with this certificate will then be enabled if your QLM administrator enabled this authentication method
- Parameters:
certificate (str) – path to the SSL certificate
- save_ssl_dn(dn: str = None, certificate: str = None)
Save a distinguished name as authentication parameter. Either dn or certificate should be provided (not both!)
Note
Calling this function will update the DN lnked to your profile on the server. Logging with a trusted certificate will then be enabled if and only if:
your certificate is trusted (i.e. signed by a certificate authority approved by the server)
the QLM administrator allows you to login with a trusted certificate
- Parameters:
dn (str, optional) – distinguished name Default: None
certificate (str, optional) – path to the SSL certificate which DN should be used Default: None
- upload_files(filenames: str | list)
Upload, to the server, the files given as argument.
Note
To upload a file, either put the path from your current working directory or give the absolute path.
from qlmaas.utils import upload_files # Uploading only one file can be done using the str signature upload_files("user/folder/file.py") # for more file uploaded, use the list signature upload_files(["user/folder/file.py", "/tmp/test2/test.txt"]
- Parameters:
filenames (str | list[str]) – string or list of filepath to upload