4 Created on Tue Jun 30 15:44:26 2020 5 Copyright 2020 Peter Rakyta, Ph.D. 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 11 http://www.apache.org/licenses/LICENSE-2.0 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see http://www.gnu.org/licenses/. 22 @author: Peter Rakyta, Ph.D. 31 from squander.decomposition.qgd_N_Qubit_Decomposition_Wrapper
import qgd_N_Qubit_Decomposition_Wrapper
47 def __init__( self, Umtx, optimize_layer_num=False, initial_guess="RANDOM" ):
50 self.qbit_num =
int(round( np.log2( len(Umtx) ) ))
53 super(qgd_N_Qubit_Decomposition, self).
__init__(Umtx, self.qbit_num, optimize_layer_num, initial_guess)
78 super(qgd_N_Qubit_Decomposition, self).
List_Gates()
85 if isinstance(gate_structure_dict, dict) :
87 for key, item
in gate_structure_dict.items():
89 if not isinstance(item, qgd_Circuit) :
90 raise Exception(
"Input parameter gate_structure_dict should be a dictionary of (int, qgd_Circuit) describing the gate structure unit cells at individual qubits")
93 raise Exception(
"Input parameter gate_structure_dict should be a dictionary of (int, qgd_Circuit) describing the gate structure unit cells at individual qubits")
112 from squander
import Qiskit_IO
114 squander_circuit = self.get_Circuit()
115 parameters = self.get_Optimized_Parameters()
117 return Qiskit_IO.get_Qiskit_Circuit( squander_circuit, parameters )
130 circuit = cirq.Circuit()
133 q = cirq.LineQubit.range(self.qbit_num)
136 gates = self.get_Gates()
139 for idx
in range(len(gates)-1, -1, -1):
143 if gate.get(
"type") ==
"CNOT":
145 circuit.append(cirq.CNOT(q[self.qbit_num-1-gate.get(
"control_qbit")], q[self.qbit_num-1-gate.get(
"target_qbit")]))
147 elif gate.get(
"type") ==
"CZ":
149 circuit.append(cirq.CZ(q[self.qbit_num-1-gate.get(
"control_qbit")], q[self.qbit_num-1-gate.get(
"target_qbit")]))
151 elif gate.get(
"type") ==
"CH":
153 circuit.append(cirq.CH(q[self.qbit_num-1-gate.get(
"control_qbit")], q[self.qbit_num-1-gate.get(
"target_qbit")]))
155 elif gate.get(
"type") ==
"SYC":
157 circuit.append(cirq.google.SYC(q[self.qbit_num-1-gate.get(
"control_qbit")], q[self.qbit_num-1-gate.get(
"target_qbit")]))
159 elif gate.get(
"type") ==
"U3":
160 print(
"Unsupported gate in the Cirq export: U3 gate")
163 elif gate.get(
"type") ==
"RX":
165 circuit.append(cirq.rx(gate.get(
"Theta")).on(q[self.qbit_num-1-gate.get(
"target_qbit")]))
167 elif gate.get(
"type") ==
"RY":
169 circuit.append(cirq.ry(gate.get(
"Theta")).on(q[self.qbit_num-1-gate.get(
"target_qbit")]))
171 elif gate.get(
"type") ==
"RZ":
173 circuit.append(cirq.rz(gate.get(
"Phi")).on(q[self.qbit_num-1-gate.get(
"target_qbit")]))
175 elif gate.get(
"type") ==
"X":
177 circuit.append(cirq.x(q[self.qbit_num-1-gate.get(
"target_qbit")]))
179 elif gate.get(
"type") ==
"SX":
181 circuit.append(cirq.sx(q[self.qbit_num-1-gate.get(
"target_qbit")]))
def get_Qiskit_Circuit(self)
Export the unitary decomposition into Qiskit format.
def Reorder_Qubits(self, qbit_list)
Call to reorder the qubits in the matrix of the gate.
def get_Cirq_Circuit(self)
Export the unitary decomposition into Qiskit format.
A QGD Python interface class for the decomposition of N-qubit unitaries into U3 and CNOT gates...
def set_Gate_Structure(self, gate_structure_dict)
Call to set the gate structure to be used in the decomposition.
def List_Gates(self)
Call to print the gates decomposing the initial unitary.
def get_Circuit(self)
Call to retrieve the incorporated quantum circuit (Squander format)
def Start_Decomposition(self)
Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition.
def __init__(self, Umtx, optimize_layer_num=False, initial_guess="RANDOM")
Constructor of the class.