def test_sidetext_with_condition(self): """Test that sidetext gates align properly with conditions""" qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") circuit = QuantumCircuit(qr, cr) circuit.append(CPhaseGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) self.circuit_drawer(circuit, cregbundle=False, filename="sidetext_condition.png")
def test_sidetext_with_condition(self): """Test that sidetext gates align properly with a condition""" filename = self._get_resource_path("test_latex_sidetext_condition.tex") qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") circuit = QuantumCircuit(qr, cr) circuit.append(CPhaseGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) circuit_drawer(circuit, cregbundle=False, filename=filename, output="latex_source") self.assertEqualToReference(filename)
def generate_entangled(self): left_circuit = QuantumCircuit(self.width, name="q") left_dag = circuit_to_dag(left_circuit) right_circuit = QuantumCircuit(self.width, name="q") right_dag = circuit_to_dag(right_circuit) qubit_targets = {qubit: set() for qubit in range(self.width)} while True: """ Apply a random two-qubit gate to either left_dag or right_dag """ random_control_qubit_idx = self.get_random_control(qubit_targets) random_target_qubit_idx = self.get_random_target( random_control_qubit_idx, qubit_targets) dag_to_apply = random.choice([left_dag, right_dag]) random_control_qubit = dag_to_apply.qubits[ random_control_qubit_idx] random_target_qubit = dag_to_apply.qubits[random_target_qubit_idx] dag_to_apply.apply_operation_back( op=CPhaseGate(theta=0.0), qargs=[random_control_qubit, random_target_qubit], cargs=[], ) qubit_targets[random_control_qubit_idx].add( random_target_qubit_idx) """ Apply a random 1-q gate to left_dag Apply its inverse to right_dag """ single_qubit_gate = random.choice( [HGate(), TGate(), XGate(), YGate(), ZGate()]) random_qubit = left_dag.qubits[random.choice(range(self.width))] left_dag.apply_operation_back(op=single_qubit_gate, qargs=[random_qubit], cargs=[]) right_dag.apply_operation_front(op=single_qubit_gate.inverse(), qargs=[random_qubit], cargs=[]) """ Terminate when there is enough depth """ if left_dag.depth() + right_dag.depth() >= self.depth: break entangled_dag = left_dag.compose(right_dag, inplace=False) entangled_circuit = dag_to_circuit(entangled_dag) num_targets = [ len(qubit_targets[qubit]) for qubit in range(self.width) ] for qubit in range(self.width): assert num_targets[qubit] <= self.num_targets_ubs[qubit] return entangled_circuit, num_targets
class TestParameterCtrlState(QiskitTestCase): """Test gate equality with ctrl_state parameter.""" @data((RXGate(0.5), CRXGate(0.5)), (RYGate(0.5), CRYGate(0.5)), (RZGate(0.5), CRZGate(0.5)), (XGate(), CXGate()), (YGate(), CYGate()), (ZGate(), CZGate()), (U1Gate(0.5), CU1Gate(0.5)), (PhaseGate(0.5), CPhaseGate(0.5)), (SwapGate(), CSwapGate()), (HGate(), CHGate()), (U3Gate(0.1, 0.2, 0.3), CU3Gate(0.1, 0.2, 0.3)), (UGate(0.1, 0.2, 0.3), CUGate(0.1, 0.2, 0.3, 0))) @unpack def test_ctrl_state_one(self, gate, controlled_gate): """Test controlled gates with ctrl_state See https://github.com/Qiskit/qiskit-terra/pull/4025 """ self.assertEqual(gate.control(1, ctrl_state='1'), controlled_gate)
def test_controlled_phase(self): """Test the creation of a controlled U1 gate.""" theta = 0.5 self.assertEqual(PhaseGate(theta).control(), CPhaseGate(theta))