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

optimize_1q_decomposition: 'NoneType' object has no attribute 'global_phase' #9842

Closed
1ucian0 opened this issue Mar 23, 2023 · 8 comments · Fixed by #9843
Closed

optimize_1q_decomposition: 'NoneType' object has no attribute 'global_phase' #9842

1ucian0 opened this issue Mar 23, 2023 · 8 comments · Fixed by #9843
Labels
bug Something isn't working

Comments

@1ucian0
Copy link
Member

1ucian0 commented Mar 23, 2023

Environment

  • Qiskit Terra version: 0.24.0.dev0+84a0fdd
  • Python version: 3.9
  • Operating system: MacOS

What is happening?

When unitary_synthesis is called with a particularly restrictive basis_gates, it seems to generate a None output as best_synth_circuit, which makes optimize_1q_decomposition raise.

How can we reproduce the issue?

from qiskit import *
circuit = QuantumCircuit(1)
circuit.append(Operator([[0.96891242+0.j        , 0.        -0.24740396j],
          [0.        -0.24740396j, 0.96891242+0.j        ]]), [0])
transpile(circuit, basis_gates=['h', 'rx']).draw()
...
<reducted>/qiskit/transpiler/passes/synthesis/unitary_synthesis.py in run(self, unitary, **options)
    741         if unitary.shape == (2, 2):
    742             _decomposer1q = Optimize1qGatesDecomposition(basis_gates, target)
--> 743             return _decomposer1q._gate_sequence_to_dag(
    744                 _decomposer1q._resynthesize_run(unitary, qubits[0])
    745             )

<reducted>/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py in _gate_sequence_to_dag(self, best_synth_circuit)
    144         out_dag = DAGCircuit()
    145         out_dag.add_qubits(qubits)
--> 146         out_dag.global_phase = best_synth_circuit.global_phase
    147 
    148         for gate_name, angles in best_synth_circuit:

AttributeError: 'NoneType' object has no attribute 'global_phase'

What should happen?

work or nicer error

Any suggestions?

No response

@1ucian0 1ucian0 added the bug Something isn't working label Mar 23, 2023
@1ucian0
Copy link
Member Author

1ucian0 commented Mar 23, 2023

Notice that transpile(circuit, basis_gates=['rx', 'ry', 'rz']) works, and returns:

   ┌─────────┐
q: ┤ Rx(0.5) ├
   └─────────┘

@jakelishman
Copy link
Member

The immediate cause for why it doesn't work is because ['h', 'rx'] isn't a combination that we have a synthesis routine for. There are no syntheses found, and the pass should return an error. Of course, we should catch that case and return a good error rather than this one, though.

@jakelishman
Copy link
Member

jakelishman commented Mar 23, 2023

To be clear, I mean UnitarySynthesis or the totality of the synthesis steps should return the error - it's part of the contract of that internal method of Optimize1qDecomposition to return None if it couldn't find a synthesis.

@jakelishman
Copy link
Member

Fixed by #9843.

@1ucian0
Copy link
Member Author

1ucian0 commented Mar 23, 2023

The immediate cause for why it doesn't work is because ['h', 'rx'] isn't a combination that we have a synthesis routine for

even when the synthesis result is a single RxGate?

@jakelishman
Copy link
Member

How would you know that the synthesis is a single rx gate without a synthesis routine that can target the general basis?

@1ucian0
Copy link
Member Author

1ucian0 commented Mar 23, 2023

I see.. so UnitarySynthesis needs to validate that you provide a "universal" basis? It is possible to do that?

@jakelishman
Copy link
Member

Whether you need a "universal" basis depends on the synthesis plugin you're using. The default one has a variety of possible universal 1q decomposers, but your basis set has to be a superset of at least one of them to work. These are the available decomposers:

ONE_QUBIT_EULER_BASIS_GATES = {
    "U3": ["u3"],
    "U321": ["u3", "u2", "u1"],
    "U": ["u"],
    "PSX": ["p", "sx"],
    "U1X": ["u1", "rx"],
    "RR": ["r"],
    "ZYZ": ["rz", "ry"],
    "ZXZ": ["rz", "rx"],
    "XZX": ["rz", "rx"],
    "XYX": ["rx", "ry"],
    "ZSXX": ["rz", "sx", "x"],
    "ZSX": ["rz", "sx"],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants