qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
297 stars 60 forks source link

How to suppress the [Qibo 0.2.0|INFO outpputs? #1528

Open Landau1908 opened 5 days ago

Landau1908 commented 5 days ago

Hi, When I run a for loop, there outputs large amounts of [Qibo 0.2.0|INFO which gives a messy display. How to suppress the [Qibo 0.2.0|INFO outpputs? Regards

[Qibo 0.2.0|INFO|2024-11-21 08:54:38]: Using qibojit (cupy) backend on /GPU:0
[Qibo 0.2.0|INFO|2024-11-21 08:54:38]: Using qibojit (cupy) backend on /GPU:0
[Qibo 0.2.0|INFO|2024-11-21 08:54:38]: Using qibojit (cupy) backend on /GPU:0
[Qibo 0.2.0|INFO|2024-11-21 08:54:38]: Using qibojit (cupy) backend on /GPU:0
...
scarrazza commented 5 days ago

@Landau1908, please update your Qibo version to the latest release and try your code again.

Landau1908 commented 4 days ago

@Landau1908, please update your Qibo version to the latest release and try your code again.

Qibo 0.2.13 gives the same outputs. Is there any options to close the outputs?

scarrazza commented 3 days ago

Could you please provide a minimal example of your code so that I can understand why this message is raised multiple times?

Landau1908 commented 2 days ago

Hi, Thank you for your continious focus. Below is a sample example.

import qibo
def qibo_test(backend, platform, threadsNumber):
    qibo.set_backend(backend, platform=platform)
    qibo.set_threads(threadsNumber)

if __name__ == "__main__":
    backend = "qibojit"
    platform = "numba"
    threadsNumber = 1
    for _ in range(3):
        qibo_test(backend, platform, threadsNumber)

Outputs:

[Qibo 0.2.13|INFO|2024-11-23 17:24:12]: Using qibojit (numba) backend on /CPU:0
[Qibo 0.2.13|INFO|2024-11-23 17:24:12]: Using qibojit (numba) backend on /CPU:0
[Qibo 0.2.13|INFO|2024-11-23 17:24:12]: Using qibojit (numba) backend on /CPU:0
alecandido commented 1 day ago

Hi @Landau1908: here you are receiving a log message each time you're setting the backend. This is triggered by this line: https://github.com/qiboteam/qibo/blob/ea6984d7594f403eeadc1e39ebbe0312a8f02716/src/qibo/backends/__init__.py#L119

An easy way to avoid that would be to check the existence and identity of the current global backend (using the get_backend() function), before attempting to set it again.

In any case, if you use the set_backend() function, that will act globally, so you do not need to set it again (unless you want to set an actually different backend). Otherwise, if you prefer to use local entities, you could just construct the backend, and pass it by value (to directly use backend.execute_circuit() for execution).

In case you still have doubts or observation, do not hesitate to reply!

marekgluza commented 6 hours ago

Hi @Landau1908

can you try this?

import qibo
def qibo_test(backend, platform, threadsNumber):
    qibo.set_backend(backend, platform=platform)
    qibo.set_threads(threadsNumber)

if __name__ == "__main__":
    backend = "qibojit"
    platform = "numba"
    threadsNumber = 1
    for _ in range(3):
        qibo_test(backend, platform, threadsNumber)

    import logging
    class SpecificWarningFilter(logging.Filter):
        def filter(self, record):
            return (
                "Using qibojit (numba) backend on"
                not in record.getMessage()
            )

    qibo_logger = qibo.config.log
    qibo_logger.addFilter(SpecificWarningFilter())

    for _ in range(3):
        qibo_test(backend, platform, threadsNumber)

(Props to @MatteoRobbiati via the boostvqe repo)

alecandido commented 2 hours ago

You can always use the env var in order to drop all the info logs:

# in the same shell in which you run your script
export QIBO_LOG_LEVEL=3

Anything >= 2 will drop all the info logs.