Skip to content

Commit

Permalink
revert Isometry.inverse change in Qiskit#8231
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Aug 5, 2022
1 parent 316eaf5 commit 133dd41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 2 additions & 9 deletions qiskit/extensions/quantum_initializer/isometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,12 @@ def _define(self):
# TODO The inverse().inverse() is because there is code to uncompute (_gates_to_uncompute)
# an isometry, but not for generating its decomposition. It would be cheaper to do the
# later here instead.
gate = self.inv_gate()
gate = gate.inverse()
gate = self.inverse().inverse()
q = QuantumRegister(self.num_qubits)
iso_circuit = QuantumCircuit(q)
iso_circuit.append(gate, q[:])
self.definition = iso_circuit

def inverse(self):
self.params = []
inv = super().inverse()
self.params = [self.iso_data]
return inv

def _gates_to_uncompute(self):
"""
Call to create a circuit with gates that take the desired isometry to the first 2^m columns
Expand Down Expand Up @@ -313,7 +306,7 @@ def validate_parameter(self, parameter):
else:
raise CircuitError(f"invalid param type {type(parameter)} for gate {self.name}")

def inv_gate(self):
def inverse(self):
"""Return the adjoint of the unitary."""
if self._inverse is None:
# call to generate the circuit that takes the isometry to the first 2^m columns
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Revert change of :class:`.Isometry` in #8231.
multiplexer instruction needs a matrix as its parameter. However,
the transpiler does not produce multiplexer with any parameters from
inverse-isometry instruction with #8231. This fix reverts a change related
to transpilation of multiplexer.
13 changes: 13 additions & 0 deletions test/python/circuit/test_uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def test_global_phase_ucg(self):

self.assertTrue(np.allclose(unitary_desired, unitary))

def test_inverse_isometry_transpile(self):
"""Test multiplexer transpiled from inverse isometry"""
qc = QuantumCircuit(1,1)
vector = [0.2, 0.1]
vector_circuit = QuantumCircuit(1)
vector_circuit.isometry(vector / np.linalg.norm(vector), [0], None)
vector_circuit = vector_circuit.inverse()
qc.append(vector_circuit, [0])

qc = transpile(qc, basis_gates=['multiplexer', 'measure'])

self.assertEqual(len(qc.data[0][0].params), 1)


def _get_ucg_matrix(squs):
return block_diag(*squs)
Expand Down

0 comments on commit 133dd41

Please sign in to comment.