qBraid icon indicating copy to clipboard operation
qBraid copied to clipboard

Challenge Accepted: Boost Our Code with Cython!

Open ryanhill1 opened this issue 1 year ago • 11 comments

CPython is renowned for its optimization capabilities, offering potential for significant performance enhancements. It's time to tap into that potential! We're inviting you to integrate CPython anywhere in our codebase and demonstrate a measurable improvement in performance.

The Challenge

Integration: Use CPython to optimize the time and/or space complexity in any part of the qBraid-SDK codebase. While improvements are welcome across the board, insiders know that the qbraid.transpiler module might just be the hidden gem you’re looking for 👀 💎 .

Demonstration: Provide statistical evidence of performance enhancements, focusing on execution time or memory usage.

Documentation: Include benchmarks, performance comparisons, and your methodology in your pull request.

ryanhill1 avatar May 15 '24 03:05 ryanhill1

Hi, I'm currently working on this issue. Can I be assigned to it?

Hope-Alemayehu avatar May 30 '24 19:05 Hope-Alemayehu

@Hope-Alemayehu Absolutely!

ryanhill1 avatar Jun 01 '24 02:06 ryanhill1

What should our priority be: optimizing for time or space? Which trade-off is less costly for Qbraid?

Hope-Alemayehu avatar Jun 01 '24 08:06 Hope-Alemayehu

@Hope-Alemayehu Both are great but I would say optimizing for time, if I had to choose!

ryanhill1 avatar Jun 01 '24 13:06 ryanhill1

@Hope-Alemayehu How are things going? If you're finding the transpiler difficult to optimize, the qbraid.interface.circuit_equality module is another greater opportunity for improvement with CPython. Matrix calculations can be extremely costly at large dimensions.

ryanhill1 avatar Jun 04 '24 03:06 ryanhill1

I was working on the transpiler and made some improvements. While I understand how to analyze the time complexity and the nature of the improvements, I found it challenging to provide statistical evidence. Would it be acceptable to present the analysis using Big O notation?

Hope-Alemayehu avatar Jun 04 '24 10:06 Hope-Alemayehu

@Hope-Alemayehu Yep that would be great!

In addition, you could use time.perf_counter() to give a ballpark measurement of the actual speed-up in milliseconds for a given operation, comparing the old code to the new. For example:

import time

# Start the timer
start_time = time.perf_counter()

# Code to measure
sum = 0
for i in range(1000000):
    sum += i

# End the timer
end_time = time.perf_counter()

# Calculate the elapsed time
elapsed_time = end_time - start_time
print(f"The code took {elapsed_time} seconds to execute.")

ryanhill1 avatar Jun 04 '24 12:06 ryanhill1

Hi @ryanhill1 @Hope-Alemayehu! Can I take this issues up to integrate CPython in the code base?

shubhamkaushal765 avatar Jun 17 '24 13:06 shubhamkaushal765

@shubhamkaushal765 Absolutely, go for it!

ryanhill1 avatar Jun 17 '24 16:06 ryanhill1

Hi @ryanhill1, Thanks!

I wanted to ask for a clarification: I believe you mean Cython instead of CPython, as the former provides the c-extension to Python which gives time/memory improvements.

from this discussion:

So CPython does not translate your Python code to C by itself. Instead, it runs an interpreter loop. There is a project that does translate Python-ish code to C, and that is called Cython. Cython adds a few extensions to the Python language, and lets you compile your code to C extensions, code that plugs into the CPython interpreter.

shubhamkaushal765 avatar Jun 18 '24 01:06 shubhamkaushal765

@shubhamkaushal765 Yes, that's what I meant! Thanks for the clarification

ryanhill1 avatar Jun 18 '24 14:06 ryanhill1