Qiskit / qiskit-serverless

A programming model for leveraging quantum and classical resources
https://qiskit.github.io/qiskit-serverless/
Apache License 2.0
68 stars 31 forks source link

Gateway: implement sets of filter to return function by specific criteria #1456

Closed IceKhan13 closed 2 months ago

IceKhan13 commented 3 months ago

What is the expected behavior?

We want to have jobs and programs endpoints to have additional filtering parameter (https:///v1/jobs?filter=).

Initially we need only 2 filters (names might change):

2 filters above are mutually exclusive.

Tansito commented 3 months ago

Do you need help with this, @IceKhan13 ?

IceKhan13 commented 3 months ago

Yes, I'm pretty busy in next few days. If somebody can take it during this time, it will be great!

akihikokuroda commented 2 months ago

@IceKhan13 Are the values below instead of "user" or "providers" ?

PRE_FILTER_KEYWORD: str = "catalog"
PRE_FILTER_KEYWORD: str = "serverless"
akihikokuroda commented 2 months ago

This is the snippet of job client. This needs some changes, doesn't it?

    def list(self, **kwargs) -> List["Job"]:
        tracer = trace.get_tracer("client.tracer")
        with tracer.start_as_current_span("job.list"):
            limit = kwargs.get("limit", 10)
            offset = kwargs.get("offset", 0)
            response_data = safe_json_request(
                request=lambda: requests.get(
                    f"{self.host}/api/{self.version}/jobs/?limit={limit}&offset={offset}",
                    headers={"Authorization": f"Bearer {self._token}"},
                    timeout=REQUESTS_TIMEOUT,
                )
            )
        return [
            Job(job.get("id"), job_client=self, raw_data=job)
            for job in response_data.get("results", [])
    ]

The /programs looks good.

def get_programs(self, **kwargs):
Tansito commented 2 months ago

@IceKhan13 Are the values below instead of "user" or "providers" ?

PRE_FILTER_KEYWORD: str = "catalog"
PRE_FILTER_KEYWORD: str = "serverless"

Open to discuss but I would not attach the client to the end-point. If other client would like to retrieve user or partner would need to use catalog or serverless. I would maintain Iskandar approach here.

akihikokuroda commented 2 months ago

user for /programs?filter=user will return function uploaded by this user only

I believe that this is the current behavior without the filter, right? @IceKhan13 @Tansito

Tansito commented 2 months ago

I believe that this is the current behavior without the filter, right? @IceKhan13 @Tansito

I would say the logic changes a little bit:

That way user always returns user functions and provider always returns provider functions. And if there is no filter I would do what we are basically doing right now: user == author && VIEW_PERMISSION