Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & use JIT compiler in pattern.py #105

Open
king-p3nguin opened this issue Dec 7, 2023 · 0 comments
Open

Refactor & use JIT compiler in pattern.py #105

king-p3nguin opened this issue Dec 7, 2023 · 0 comments
Labels
new feature New feature or request

Comments

@king-p3nguin
Copy link
Contributor

king-p3nguin commented Dec 7, 2023

In #98, I added rustworkx as a backend for the graph state simulator, but sadly, the performance improvement was subtle.
I think this is because most of the optimization process is done in pattern.py, not in GraphState.

Refactoring the code might improve the performance. For example, the following code searches all the command sequences to find the measurement command, but we can make a list of indices where the measurement commands are stored during the pattern standardization and save it as an attribute in the Pattern class.

graphix/graphix/pattern.py

Lines 1792 to 1801 in 8313d3c

for cmd in pattern.seq:
if cmd[0] == "M":
if cmd[1] in list(graph_state.nodes):
cmd_new = deepcopy(cmd)
new_clifford_ = vops[cmd[1]]
if len(cmd_new) == 7:
cmd_new[6] = new_clifford_
else:
cmd_new.append(new_clifford_)
new_seq.append(cmd_new)

It also scans the whole command sequence twice, which looks redundant.

graphix/graphix/pattern.py

Lines 1806 to 1808 in 8313d3c

for cmd in pattern.seq:
if cmd[0] == "X" or cmd[0] == "Z":
new_seq.append(cmd)

Another suggestion is to use JIT compiler (e.g. numba, jax). Wrapping frequently called functions by jit may improve performance.

@king-p3nguin king-p3nguin added the new feature New feature or request label Dec 7, 2023
@king-p3nguin king-p3nguin changed the title Refactor & use JIT in pattern.py Refactor & use JIT compiler in pattern.py Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant