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

Remove _t_complexity_ if build_call_graph exists #1044

Merged
merged 9 commits into from
Jun 11, 2024

Conversation

dstrain115
Copy link
Contributor

@dstrain115 dstrain115 commented Jun 3, 2024

  • If call graph exists, then the t complexity is redundant. These t_complexities are moved to tests to ensure that the t_complexity is as expected.

  • Only issue is LPRSInterimPrep no longer supports symbolics for t_complexity.

Fixes: #905

- If call graph exists, then the t complexity is redundant.
These t_complexities are moved to tests to ensure that the
t_complexity is as expected.

- Only issue is LPRSInterimPrep whose _t_complexity_ is not consistent.
Comment on lines 41 to 45
def test_lp_resource_state_symb():
bloq = _lp_resource_state_symbolic.make()
assert bloq.t_complexity().t == 4 * bloq.bitsize


Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we should keep this test marked @pytest.mark.xfail? (so that we don't forget to fix symbolics for LPRS.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM, Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not ideal to have the symbolis not working -- maybe it's best to wait till we can add a CRz Bloq and use that so we can continue to support symbolics.

I don't think there's any rush to remove t_complexity; especially by breaking symbolic resource counting which is a lot more useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this and reenabled symbolics.

@@ -94,9 +93,6 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
}
return ret

def _t_complexity_(self) -> 'TComplexity':
return TComplexity(rotations=self.bitsize + 1, clifford=2 + self.bitsize)
Copy link
Contributor

Choose a reason for hiding this comment

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

@tanujkhattar isn't this TComplexity expression wrong? we use self.bitsize CRz gates but TComplexity.rotations is only for single qubit rotations, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is totally wrong. Even if we revert the change to fix symbolics, this expression still needs to change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We often use rotations in TComplexity to count up both 1 and 2 qubit rotations (though ideally it should be just 1 qubit phase rotations). Another example is CZPowGate -

class CZPowGate(CirqGateAsBloqBase):
where we set rotations=1. This is actually fine since CZPowGate has a decomposition where we can use only 1 ZPow rotation + 2 Toffoli gates.

Eventually, I think these fundamental 1 and 2 qubit rotation gates should be leaf nodes that we count up and user can choose to how to decompose them; which has a constant additive or small multiplicative overhead.

Tl;Dr - I'm fine with updating the expression now but we should add a comment explaining why we have the constant overhead of 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the t_complexity removal, and added a comment. Let me know if I misrepresented the factor in the comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should make this change in a different PR? because it's a bug-fix for the tcomplexity expression, unlike the other changes that remove _t_complexity_

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that's necessary

Comment on lines +98 to +99
# Uses self.bitsize controlled-Rz rotations which decomposes into
# 2 single-qubit rotations and 3 cliffords
Copy link
Contributor

Choose a reason for hiding this comment

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

source?

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

In the interest of moving things forward, and because this leaves everything strictly in as-good or a better place than it was before: let's merge. Interested parties can do the CRz implementation and fix in a following PR

@mpharrigan mpharrigan merged commit 0188c93 into quantumlib:main Jun 11, 2024
7 checks passed
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.

Remove _t_complexity_ overrides where build_call_graph exists.
4 participants