Public API
System design of the Tergite public API
The public API is the Main Service Server (MSS) in tergite-frontend, a FastAPI application backed by MongoDB or PostgreSQL. It owns the users, projects, jobs, the devices’ calibrations and the notices, talks to the backends on its users’ behalf, and serves the dashboard at /ui.
Flows
Initializing experiment
The Tergite SDK sends a request to the Tergite public API to initialize the experiment for a given backend.
The public API creates an empty job with a unique ID and saves it in its database. It asks the backend for a job token, and responds to the SDK with the job ID, the token and the URL of the backend.
Updating experiment results
The Tergite SDK uploads the experiment(s), as OpenQASM 3 circuits, with the job token to the Tergite backend. The Tergite backend runs the experiments and sends the results to the Tergite public API over the device’s websocket, /devices/ws/{name}.
The public API updates the job in the database with the status of the run and the results, if any, of the experiment(s), and takes the job’s run time off its project’s QPU seconds.
Retrieving experiment results
The Tergite SDK then requests the Tergite public API for the results. The public API then reads the results from its database and responds to the SDK with them.
Special Techniques
Authentication
Users log in through OAuth2 or OpenID Connect providers, the [[auth.clients]] of mss-config.toml; there is no password login. A logged-in user holds a JWT, as a cookie in the dashboard or a bearer token, which works on the /auth, /me and /admin endpoints. The SDK uses an app token instead, which a user creates for one of their projects and which works on the resource endpoints such as /jobs.
The public API and each backend authenticate each other with RSA key pairs: MSS signs its requests to a backend with its private key, and a backend signs its websocket connection to MSS with its own, which MSS checks with the public_key_path of that backend’s [[backends]] entry. See Authentication.
Accounting
Each project has QPU seconds. A job can only be created with an app token of a project with positive QPU seconds, and the time a job ran is taken off its project’s QPU seconds when its backend reports it. Users ask for more QPU seconds with requests that superusers decide. See Resource Management.