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

filter_function for circuit.depth() and circuit.size() #6998

Merged
merged 8 commits into from
Sep 13, 2021

Conversation

ajavadia
Copy link
Member

@ajavadia ajavadia commented Sep 9, 2021

adding the ability to filter by instructions when inquiring circuit.depth() or circuit.size()

closes #6702

@ajavadia ajavadia requested a review from ecpeterson September 9, 2021 14:24
@ajavadia ajavadia requested a review from a team as a code owner September 9, 2021 14:24
qiskit/circuit/quantumcircuit.py Outdated Show resolved Hide resolved
qiskit/circuit/quantumcircuit.py Outdated Show resolved Hide resolved

Args:
filter_function (callable): a function to filter out some instructions.
Should take as input a tuple of (Instruction, list(Qubit), list(Clbit)).
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it makes more sense to flatten this one layer and use 3 positional args. It might be easier for people to create functions like:

def filter_fn(instruction, qargs, cargs):

instead of:

def filter_fn(inst_tuple):
    instruction = inst_tuple[0]
    qargs =  inst_tuple[1]
    cargs =  inst_tuple[2]

Copy link
Member Author

Choose a reason for hiding this comment

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

I intentionally did it this way because I think we really need something in Qiskit to represent the tuple (inst, qubit, clbits). I was actually going to do that as a followup, using a namedtuple or something. It comes up over and over again that you need the operation plus the operands. I think that is the basic unit of a circuit (i.e. one line of qasm).

@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Sep 9, 2021
Copy link
Contributor

@ecpeterson ecpeterson left a comment

Choose a reason for hiding this comment

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

Tests indicate something that needs fixing.

qiskit/circuit/quantumcircuit.py Outdated Show resolved Hide resolved
@ajavadia ajavadia merged commit 7c30a6e into Qiskit:main Sep 13, 2021
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

function to calculate 2-qubit gate depth
4 participants