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.gates.qgd_Circuit_Wrapper
import qgd_Circuit_Wrapper
36 from squander.gates.gates_Wrapper
import (
74 def __getstate__(self): 75 # Return a dictionary of the object's state 77 return super().__getstate__() 79 def __setstate__(self, state): 82 super().__setstate__( state ) 85 def __new__(cls, *args, **kwargs): 87 print( "NEEEEEEEEEEEEEW", args) 88 return super().__new__(cls, *args, **kwargs) 98 super().
add_U1(target_qbit)
107 super().
add_U2(target_qbit)
116 super().
add_U3(target_qbit)
125 super().
add_RX(target_qbit)
133 super().
add_R(target_qbit)
142 super().
add_RY(target_qbit)
151 super().
add_RZ(target_qbit)
160 super().
add_CNOT(target_qbit, control_qbit)
166 def add_CZ( self, target_qbit, control_qbit):
169 super().
add_CZ(target_qbit, control_qbit)
175 def add_CH( self, target_qbit, control_qbit):
178 super().
add_CH(target_qbit, control_qbit)
184 def add_SYC( self, target_qbit, control_qbit):
187 super().
add_SYC(target_qbit, control_qbit)
197 super().
add_H(target_qbit)
206 super().
add_X(target_qbit)
215 super().
add_Y(target_qbit)
224 super().
add_Z(target_qbit)
233 super().
add_SX(target_qbit)
242 super().
add_T(target_qbit)
266 def add_CROT( self, target_qbit, control_qbit, subtype):
269 super(qgd_Circuit, self).
add_CROT(target_qbit, control_qbit, subtype)
302 def apply_to( self, parameters_mtx, unitary_mtx, parallel=1):
305 super().
apply_to( parameters_mtx, unitary_mtx, parallel=parallel )
319 qbit_num = self.get_Qbit_Num()
321 qubit_list_validated = list()
322 if isinstance(qubit_list, list)
or isinstance(qubit_list, tuple):
323 for item
in qubit_list:
324 if isinstance(item, int):
325 qubit_list_validated.append(item)
326 qubit_list_validated = list(set(qubit_list_validated))
328 print(
"Elements of qbit_list should be integers")
330 elif qubit_list ==
None:
331 qubit_list_validated = [ x
for x
in range(qbit_num) ]
334 print(
"Elements of qbit_list should be integers")
338 if parameters
is None:
339 print(
"get_Second_Renyi_entropy: array of input parameters is None")
343 if input_state
is None:
344 matrix_size = 1 << qbit_num
345 input_state = np.zeros( (matrix_size,1), dtype=np.complex128 )
396 qbit_num = self.get_Qbit_Num()
428 gates = self.get_Gates()
432 while (len(used_gates_idx) != len(gates)):
434 gate_start_idx_prev = gate_start_idx
435 gate_idx = gate_start_idx
437 control_last_single=[
False]*self.qbit_num
439 while((len(involved_qbits)<self.qbit_num)
and gate_idx<len(gates)):
440 if gate_idx
not in used_gates_idx:
443 gate = gates[gate_idx]
444 if isinstance( gate, qgd_CROT ):
445 if ((control_qbit
in involved_qbits)
and control_last_single[control_qbit]==
False)
and (target_qbit
not in involved_qbits):
446 involved_qbits.append(target_qbit)
447 used_gates_idx.append(gate_idx)
448 gate_group.append(gate_idx)
449 control_last_single[control_qbit]=
False 450 elif ((control_qbit
in involved_qbits)
and control_last_single[control_qbit]==
True)
and (target_qbit
not in involved_qbits):
451 involved_qbits.append(target_qbit)
452 if (gate_start_idx == gate_start_idx_prev):
453 gate_start_idx=gate_idx
454 elif (control_qbit
not in involved_qbits)
and (target_qbit
not in involved_qbits):
455 involved_qbits.append(target_qbit)
456 involved_qbits.append(control_qbit)
457 used_gates_idx.append(gate_idx)
458 gate_group.append(gate_idx)
459 control_last_single[control_qbit]=
False 460 elif (gate_start_idx == gate_start_idx_prev):
461 gate_start_idx=gate_idx
464 if (control_qbit
not in involved_qbits)
and (target_qbit
not in involved_qbits):
465 involved_qbits.append(target_qbit)
466 involved_qbits.append(control_qbit)
467 used_gates_idx.append(gate_idx)
468 gate_group.append(gate_idx)
469 elif (gate_start_idx == gate_start_idx_prev):
470 gate_start_idx=gate_idx
472 control_last_single[target_qbit]=
True 473 if target_qbit
not in involved_qbits:
474 involved_qbits.append(target_qbit)
475 used_gates_idx.append(gate_idx)
476 control_last_single[target_qbit]=
True 477 gate_group.append(gate_idx)
478 elif (gate_start_idx == gate_start_idx_prev):
479 gate_start_idx=gate_idx
481 gate_groups.append(gate_group)
489 if isinstance(qgd_gate,H):
490 self.add_H(qgd_gate.get_Target_Qbit())
491 elif isinstance(qgd_gate,X):
492 self.add_X(qgd_gate.get_Target_Qbit())
493 elif isinstance(qgd_gate,Y):
494 self.add_Y(qgd_gate.get_Target_Qbit())
495 elif isinstance(qgd_gate,Z):
496 self.add_Z(qgd_gate.get_Target_Qbit())
497 elif isinstance(qgd_gate,CH):
498 self.add_CH(qgd_gate.get_Target_Qbit(),qgd_gate.get_Control_Qbit())
499 elif isinstance(qgd_gate,CZ):
500 self.add_CZ(qgd_gate.get_Target_Qbit(),qgd_gate.get_Control_Qbit())
501 elif isinstance(qgd_gate,RX):
502 self.add_RX(qgd_gate.get_Target_Qbit())
503 elif isinstance(qgd_gate,RY):
504 self.add_RY(qgd_gate.get_Target_Qbit())
505 elif isinstance(qgd_gate,RZ):
506 self.add_RZ(qgd_gate.get_Target_Qbit())
507 elif isinstance(qgd_gate,SX):
508 self.add_SX(qgd_gate.get_Target_Qbit())
509 elif isinstance(qgd_gate,U1):
510 self.add_U1(qgd_gate.get_Target_Qbit())
511 elif isinstance(qgd_gate,U2):
512 self.add_U2(qgd_gate.get_Target_Qbit())
513 elif isinstance(qgd_gate,U3):
514 self.add_U3(qgd_gate.get_Target_Qbit())
515 elif isinstance(qgd_gate,CRY):
516 self.add_CRY(qgd_gate.get_Target_Qbit(),qgd_gate.get_Control_Qbit())
517 elif isinstance(qgd_gate,CNOT):
518 self.add_CNOT(qgd_gate.get_Target_Qbit(),qgd_gate.get_Control_Qbit())
519 elif isinstance(qgd_gate,T):
520 self.add_T(qgd_gate.get_Target_Qbit())
521 elif isinstance(qgd_gate,Tdg):
522 self.add_Tdg(qgd_gate.get_Target_Qbit())
523 elif isinstance(qgd_gate,R):
524 self.add_R(qgd_gate.get_Target_Qbit())
525 elif isinstance(qgd_gate,qgd_CROT):
526 self.add_CROT(qgd_gate.get_Target_Qbit(),qgd_gate.get_Control_Qbit(),qgd_gate.subtype)
528 raise Exception(
"Cannot add gate: unimplemented gate type")
def add_Y(self, target_qbit)
def get_Parameter_Start_Index(self)
def add_CNOT(self, target_qbit, control_qbit)
def get_Qbit_Num(self)
Call to get the number of qubits in the circuit.
def add_SX(self, target_qbit)
A QGD Python interface class for the Gates_Block.
def add_SYC(self, target_qbit, control_qbit)
def add_T(self, target_qbit)
def get_Circuit_Depth(self)
def get_Second_Renyi_Entropy(self, parameters=None, input_state=None, qubit_list=None)
Call to get the second Rényi entropy.
def add_CH(self, target_qbit, control_qbit)
def add_X(self, target_qbit)
def get_Gates(self)
Call to get the list of gates (or subcircuits) in the circuit.
def get_Gate_Nums(self)
Call to get statisctics on the gate counts in the circuit.
def add_RY(self, target_qbit)
def add_R(self, target_qbit)
def add_RZ(self, target_qbit)
def add_CROT(self, target_qbit, control_qbit, subtype)
def Remap_Qbits(self, qbit_map, qbit_num=None)
Call to remap the qubits in the circuit.
def get_Matrix(self, parameters_mtx)
def add_CZ(self, target_qbit, control_qbit)
def add_H(self, target_qbit)
def add_RX(self, target_qbit)
def add_adaptive(self, target_qbit, control_qbit)
def apply_to(self, parameters_mtx, unitary_mtx, parallel=1)
def get_Parameter_Num(self)
def add_Tdg(self, target_qbit)
def get_Parents(self, gate)
def __init__(self, qbit_num)
Constructor of the class.
def get_Qbits(self)
Call to get the list of qubits involved in the circuit.
def get_Children(self, gate)
def add_U1(self, target_qbit)
def add_U3(self, target_qbit)
def add_Circuit(self, gate)
def get_Control_Qbit(self)
def add_U2(self, target_qbit)
def add_Z(self, target_qbit)
def add_Gate(self, qgd_gate)
def get_Target_Qbit(self)