Skip to content

t_complexity doesn't work for StatePreparationAliasSampling #935

@mstechly

Description

@mstechly

When I run this:

bloq = StatePreparationAliasSampling.from_lcu_probs([0.25, 0.5, 0.25], probability_epsilon=0.05)
bloq.t_complexity()

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/_infra/bloq.py", line 420, in t_complexity
    return t_complexity(self)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 240, in t_complexity
    ret = _t_complexity_for_gate_or_op(stc)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/cachetools/__init__.py", line 675, in wrapper
    v = func(*args, **kwargs)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 224, in _t_complexity_for_gate_or_op
    return _t_complexity_from_strategies(gate_or_op, strategies)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 204, in _t_complexity_from_strategies
    ret = strategy(stc)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 163, in _from_bloq_build_call_graph
    r = t_complexity(bloq)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 240, in t_complexity
    ret = _t_complexity_for_gate_or_op(stc)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/cachetools/__init__.py", line 675, in wrapper
    v = func(*args, **kwargs)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 224, in _t_complexity_for_gate_or_op
    return _t_complexity_from_strategies(gate_or_op, strategies)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 204, in _t_complexity_from_strategies
    ret = strategy(stc)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/cirq_interop/t_complexity_protocol.py", line 157, in _from_bloq_build_call_graph
    _, sigma = stc.call_graph(max_depth=1, generalizer=cirq_to_bloqs)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/_infra/bloq.py", line 327, in call_graph
    return get_bloq_call_graph(self, generalizer=generalizer, keep=keep, max_depth=max_depth)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/resource_counting/bloq_counts.py", line 225, in get_bloq_call_graph
    _build_call_graph(bloq, generalizer, ssa, keep, max_depth, g=g, depth=0)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/resource_counting/bloq_counts.py", line 120, in _build_call_graph
    callee_counts = _generalize_callees(bloq.build_call_graph(ssa), generalizer)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/bloqs/multiplexers/unary_iteration_bloq.py", line 622, in build_call_graph
    unary_iteration_loops(0, {}, total_bits(self.control_registers))
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/bloqs/multiplexers/unary_iteration_bloq.py", line 618, in unary_iteration_loops
    unary_iteration_loops(nested_depth + 1, selection_reg_name_to_val, num_controls=1)
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/bloqs/multiplexers/unary_iteration_bloq.py", line 603, in unary_iteration_loops
    for bloq, count in self.nth_operation_callgraph(**selection_reg_name_to_val):
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/bloqs/data_loading/qrom.py", line 236, in nth_operation_callgraph
    return {(CNOT(), sum(int(d[selection_idx]).bit_count() for d in self.data))}
  File "/Users/mstechly/.pyenv/versions/2024-05-07-qualtran-conversion/lib/python3.9/site-packages/qualtran/bloqs/data_loading/qrom.py", line 236, in <genexpr>
    return {(CNOT(), sum(int(d[selection_idx]).bit_count() for d in self.data))}
AttributeError: 'int' object has no attribute 'bit_count'

Extra comments:

  1. I want to do the same on the decomposed version of this bloq (.decompose_bloq()), and both fail the same way.
  2. Is t_complexity the main way to get the costs of a given bloq or is there some other way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions