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

Add UniQ partitioning algorithm #16

Closed
wants to merge 2 commits into from

Conversation

fxfxfxfxfxfxfxfx
Copy link
Collaborator

No description provided.

Copy link
Owner

@Zhaoyilunnn Zhaoyilunnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great job. Left some comments.

return sub_circs


class dptask:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming convention please follow google style guide

self.gateNum = gateNum
self.qubitNum = qubitNum

def addGate(self, gateIndex: int, gatePos):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, please refer to the style guide.

In short

  • For classes, use CamelCase convention.
  • For methods, variables, use lower_case_with_underscore convention.



class UniQPartitioner(BasePartitioner):
"""Partitioner in UniQ"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to add a reference here. Refer to sphinx docstring sections to see commonly used keywords.

Currently, we're not creating a document website. But trying to write standard docstrings will reduce lots of effort once we need to have a website holding documentation of this project.

"""
References:
    [1] <the-paper-link>
"""


def run(self, circuit: Any) -> List[QdaoCircuit]:
self._circ_helper.circ = circuit
ops = copy.deepcopy(self._circ_helper.instructions)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to make a deep copy of instructions? If necessary, we need to measure the performance overhead when circuit becomes very large with a large number of instructions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because after each selection of a subcircuit, the selected gate must be removed and preprocessed again. In order not to affect the original data, a deep copy operation is selected. This really isn't necessary and if it would cause a performance hit, I would build an array to record this kind of property.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on my understanding, all operations you performed on ops is pop() and get(). As long as we do not need to modify, i.e., write to, the value of ops[i]. There's no need to use deepcopy.

return (opList, numQubit)


class UniQPartitioner(BasePartitioner):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should consider registering UniQPartitioner into PARTITIONERS. This is somehow a naive factory design pattern offering better maintainablility. We could discuss more elegant practice.

set(self.result_op[gateIndex + 1][j])
)

def createTask(self, ops):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function name will confuse users and developers. Basically, we already defined DpTask class, and one might think that DpTask() will create a task object. So I suggest to consider better naming to distinguish this function from vanilla DpTask instantiation.

@@ -0,0 +1,48 @@
from qiskit import transpile
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we do not need to commit this file into this project. If necessary, it would be better to appear in our test directory

Comment on lines +206 to +207
print("----------UniqPartitioner-----------")
print("num of sub-circuits:" + str(len(sub_circs)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to use logging, if this is just used for testing, it is not necessary to commit these lines.

active = self._np
m = self._circ_helper.circ.num
sub_circs = []
while len(ops) != 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> 0 is enough.

bitList = self.result_bit[i + 1][j]
numQubit = len(self.result_bit[i + 1][j])
numOp = len(self.result_op[i + 1][j])
return (opList, numQubit)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary to explicitly use tuple. return op_list, num_qubits would be enough

@Zhaoyilunnn
Copy link
Owner

Firstly, we need to fix unit test, it seems that current implementation is not compatible with python3.8.
Then you may refer to my comments. Most are just coding style issues.

@fxfxfxfxfxfxfxfx
Copy link
Collaborator Author

There are indeed many problems with the code, thank you for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants