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

Pass Manager for Swap Optimal circuits raises errors for linear Pauli Strings #1

Open
JanikSchoenmeierKromer opened this issue Sep 29, 2023 · 2 comments

Comments

@JanikSchoenmeierKromer
Copy link

Describe the issue:

The PassManager in Step 2 "Apply Swap strategies" from the "how_to_build_qaoa_swap_circuit.ipynb" notebook raises an error message for "linear" Pauli Strings in the SparsePauliOp (e.g. 'ZIIIIIIIII'; containing only a single Z Pauli and Identities otherwise instead of the exemplary used two Z Pauli strings, e.g. 'ZZIIIIIIII') . These linear terms can be relevant for optimization problems.

Reproduce the code example:

Initializing the Sparse Pauli Operator in the notebook with an additional Pauli String and coeeficient of the form ['ZIIIIIIIII', 1.] and running the notebook reproduces the error.
E.g. Insert the following code instead of the second cell of the notebook and continue all steps including calling swapped_cost_layer = pm_pre.run(cost_layer).

from qiskit.quantum_info import SparsePauliOp

local_correlators = [['ZIIIIIIIII', 1.],['IIIIIZZIII', 1.], ['IIIIIIZIZI', 1.0], ['IIIIIIZIIZ', 1.0], ['ZIIIIZIIII', 1.0], ['IIIIZZIIII', 1.0], ['IIZIIIIZII', 1.0], ['IZZIIIIIII', 1.0], ['IIZZIIIIII', 1.0], ['IIIIIIIZZI', 1.0], ['IIIIZIIZII', 1.0], ['IIIIZIIIIZ', 1.0], ['IIIIIIIIZZ', 1.0], ['ZZIIIIIIII', 1.0], ['IZIZIIIIII', 1.0], ['ZIIZIIIIII', 1.0]]
cost_operator = SparsePauliOp.from_list(local_correlators)
print(cost_operator)

Error message:

    280 """Run all the passes on a ``circuit``.
    281 
    282 Args:
   (...)
...
    110 if len(edge) != 2:
--> 111     raise QiskitError(f"{pauli} does not have length two.")
    113 return edge

QiskitError: 'ZIIIIIIIII does not have length two.'
@eggerdj
Copy link
Collaborator

eggerdj commented Oct 8, 2023

Thanks for raising this. We could handle this case in create_qaoa_swap_circuit


I would handle terms with a single Z by filtering them out and creating a layer of Rz gates (applied on qubits that should have one). This layer of Rz gates must then be applied before the layers of Rzz's of the quadratic term when p is odd and after the layers of Rzz's when p is even.

@JanikSchoenmeierKromer
Copy link
Author

Thank you for the proposed solution and explanation.

ElePT pushed a commit to ElePT/qopt-best-practices that referenced this issue Mar 3, 2024
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

No branches or pull requests

2 participants