Skip to content

Commit

Permalink
feat: optional 1q gates to numerical decomp ansatz
Browse files Browse the repository at this point in the history
  • Loading branch information
evmckinney9 committed Aug 21, 2023
1 parent f6d889b commit e4526f0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/transpile_benchy/utilities/numerical_decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class CircuitAnsatzDecomposer(ABC):
reinitialize_attempts = 1
default_threshold = 1e-8

def __init__(self, basis_gates: list[UnitaryGate]):
def __init__(self, basis_gates: list[UnitaryGate], include_1q=True):
"""Initialize the CircuitAnsatzDecomposer class.
Args:
target: The unitary target to be decomposed.
basis_gates: The basis gates to be used in the decomposition.
include_1q: (True) Whether to include interleaving 1Q gates in the ansatz.
"""
self.basis_gates = basis_gates
self.include_1q = include_1q
# assert that all basis_gates >= 2 qubits
# assert all([basis_gate[0].num_qubits >= 2 for basis_gate in basis_gates])

Expand Down Expand Up @@ -76,7 +78,8 @@ def decompose(self, target: UnitaryGate) -> QuantumCircuit:
self.best_cost = None

self.ansatz = QuantumCircuit(self.num_qubits)
self._initialize_1Q_gates()
if self.include_1q:
self._initialize_1Q_gates()

iterations = 0
while not self.converged and iterations < self.max_iterations:
Expand Down Expand Up @@ -235,13 +238,14 @@ def _linear_placement(self) -> None:
self.ansatz.append(basis_gate, edge_indices)

# append 1Q gates to all qubits the basis gate was just on
for i in edge_indices:
u_params = [
Parameter(f"p{i:03}")
for i in range(self.parameter_count, self.parameter_count + 3)
]
self.parameter_count += 3
self.ansatz.append(UGate(*u_params), [i])
if self.include_1q:
for i in edge_indices:
u_params = [
Parameter(f"p{i:03}")
for i in range(self.parameter_count, self.parameter_count + 3)
]
self.parameter_count += 3
self.ansatz.append(UGate(*u_params), [i])

# wrap index around for linear placement
self.basis_gate_index += 1
Expand Down

0 comments on commit e4526f0

Please sign in to comment.