def test_optimization_condition(self, level):
     """Test optimization levels with condition in the circuit"""
     qr = QuantumRegister(2)
     cr = ClassicalRegister(1)
     qc = QuantumCircuit(qr, cr)
     qc.cx(0, 1).c_if(cr, 1)
     backend = FakeJohannesburg()
     circ = transpile(qc, backend, optimization_level=level)
     self.assertIsInstance(circ, QuantumCircuit)
 def test_alignment_constraints_called_with_by_default(self, level):
     """Test that TimeUnitConversion is not called if there is no delay in the circuit."""
     q = QuantumRegister(2, name="q")
     circuit = QuantumCircuit(q)
     circuit.h(q[0])
     circuit.cz(q[0], q[1])
     with unittest.mock.patch("qiskit.transpiler.passes.TimeUnitConversion.run") as mock:
         transpile(circuit, backend=FakeJohannesburg(), optimization_level=level)
     mock.assert_not_called()
 def test_alignment_constraints_called_with_delay_in_circuit(self, level):
     """Test that TimeUnitConversion is called if there is a delay in the circuit."""
     q = QuantumRegister(2, name="q")
     circuit = QuantumCircuit(q)
     circuit.h(q[0])
     circuit.cz(q[0], q[1])
     circuit.delay(9.5, unit="ns")
     with unittest.mock.patch(
         "qiskit.transpiler.passes.TimeUnitConversion.run", return_value=circuit_to_dag(circuit)
     ) as mock:
         transpile(circuit, backend=FakeJohannesburg(), optimization_level=level)
     mock.assert_called_once()
oneQ_oneC_gates = [Measure]
variadic_gates = [Barrier]

mock_backends = [
    FakeYorktown(),
    FakeTenerife(),
    FakeOurense(),
    FakeVigo(),
    FakeMelbourne(),
    FakeRueschlikon(),
    FakeTokyo(),
    FakePoughkeepsie(),
    FakeAlmaden(),
    FakeSingapore(),
    FakeJohannesburg(),
    FakeBoeblingen()
]

# FakeRochester disabled until https://github.com/Qiskit/qiskit-aer/pull/693 is released.


@settings(report_multiple_bugs=False,
          max_examples=25,
          deadline=None,
          suppress_health_check=[HealthCheck.filter_too_much])
class QCircuitMachine(RuleBasedStateMachine):
    """Build a Hypothesis rule based state machine for constructing, transpiling
    and simulating a series of random QuantumCircuits.

    Build circuits with up to QISKIT_RANDOM_QUBITS qubits, apply a random
threeQ_gates = [CCXGate, CSwapGate]

oneQ_oneP_gates = [U1Gate, RXGate, RYGate, RZGate]
oneQ_twoP_gates = [U2Gate]
oneQ_threeP_gates = [U3Gate]

twoQ_oneP_gates = [CRZGate, RZZGate, CU1Gate]
twoQ_threeP_gates = [CU3Gate]

oneQ_oneC_gates = [Measure]
variadic_gates = [Barrier]

mock_backends = [FakeYorktown(), FakeTenerife(), FakeOurense(), FakeVigo(),
                 FakeMelbourne(), FakeRueschlikon(),
                 FakeTokyo(), FakePoughkeepsie(), FakeAlmaden(), FakeSingapore(),
                 FakeJohannesburg(), FakeBoeblingen()]

# FakeRochester disabled until https://github.com/Qiskit/qiskit-aer/pull/693 is released.


@settings(report_multiple_bugs=False,
          max_examples=25,
          deadline=None,
          suppress_health_check=[HealthCheck.filter_too_much])
class QCircuitMachine(RuleBasedStateMachine):
    """Build a Hypothesis rule based state machine for constructing, transpiling
    and simulating a series of random QuantumCircuits.

    Build circuits with up to QISKIT_RANDOM_QUBITS qubits, apply a random
    selection of gates from qiskit.circuit.library with randomly selected
    qargs, cargs, and parameters. At random intervals, transpile the circuit for