Qiskit/qiskit_humaneval huggingface dataset:
from qiskit import QuantumCircuit
def create_quantum_circuit(n_qubits):
    """ Generate a Quantum Circuit for the given int 'n_qubits' and return it.
    """
    return QuantumCircuit(n_qubits)


def check(candidate):
    result = candidate(3)
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 3
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def run_bell_state_simulator():
    """ Define a phi plus bell state using Qiskit, transpile the circuit using pass manager with optimization level as 1, run it using Qiskit Sampler with the Aer simulator as backend and return the counts dictionary.
    """
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0, 1)
    bell.measure_all()
    backend = AerSimulator()
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend)
    isa_circuit = pass_manager.run(bell)
    sampler = Sampler(mode=backend)
    result = sampler.run([isa_circuit], shots=1000).result()
    return result[0].data.meas.get_counts()


def check(candidate):
    result = candidate()
    assert isinstance(result, dict)
    assert result.keys() == {"00", "11"}
    assert 0.4 < (result["00"] / sum(result.values())) < 0.6
from qiskit.quantum_info import Statevector
from math import sqrt
def create_bell_statevector() -> Statevector:
    """ Return a phi+ Bell statevector.
    """
    return (Statevector.from_label("00") + Statevector.from_label("11")) / sqrt(2)


def check(candidate):
    result = candidate()
    solution = (Statevector.from_label("00") + Statevector.from_label("11")) / sqrt(2)
    assert result.equiv(solution)
from qiskit import QuantumCircuit
def create_ghz(drawing=False):
    """ Generate a QuantumCircuit for a 3 qubit GHZ State and measure it. If `drawing` is True, return both the circuit object and the Matplotlib drawing of the circuit, otherwise return just the circuit object.
    """
    ghz = QuantumCircuit(3)
    ghz.h(0)
    ghz.cx(0, 1)
    ghz.cx(0, 2)
    ghz.measure_all()
    if drawing:
        return ghz, ghz.draw(output="mpl")
    return ghz

def check(candidate):
    from qiskit.quantum_info import Statevector
    import math
    import matplotlib

    def check_circuit(circuit):
        assert circuit.data[-1].operation.name == "measure"
        circuit.remove_final_measurements()
        ghz_statevector = (
            Statevector.from_label("000") + Statevector.from_label("111")
        ) / math.sqrt(2)
        assert Statevector.from_instruction(circuit).equiv(ghz_statevector)

    circuit = candidate()
    check_circuit(circuit)

    circuit, drawing = candidate(drawing=True)
    check_circuit(circuit)
    assert isinstance(drawing, matplotlib.figure.Figure)
from qiskit import QuantumCircuit
def create_unitary_from_matrix():
    """ Write the function that converts the matrix [[0, 0, 0, 1],[0, 0, 1, 0],[1, 0, 0, 0],[0, 1, 0, 0]] into a unitary gate and apply it to a Quantum Circuit. Then return the circuit.
    """
    matrix = [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0]]
    circuit = QuantumCircuit(2)
    circuit.unitary(matrix, [0, 1])
    return circuit


def check(candidate):
    from qiskit.quantum_info import Operator
    matrix = [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0]]
    solution = QuantumCircuit(2)
    solution.unitary(matrix, [0, 1])
    assert Operator(solution).equiv(Operator(candidate()))
from qiskit import QuantumCircuit
def create_state_prep():
    """ Return a QuantumCircuit that prepares the binary state 1.
    """
    qc = QuantumCircuit(2)
    qc.prepare_state("01")
    return qc


def check(candidate):
    from qiskit.quantum_info import Statevector
    candidate_circuit = candidate()
    assert isinstance(candidate_circuit, QuantumCircuit)
    candidate_sv = Statevector.from_instruction(candidate())
    refrence_sv = Statevector.from_label("1".zfill(candidate_sv.num_qubits))
    assert candidate_sv.equiv(refrence_sv)
from qiskit import QuantumCircuit


def create_state_prep(num_qubits):
    """ Return a QuantumCircuit that prepares the state |1> on an n-qubit register.
    """
    qc = QuantumCircuit(num_qubits)
    qc.prepare_state(1)
    return qc


def check(candidate):
    from qiskit.quantum_info import Statevector

    candidate_circuit = candidate(num_qubits=5)
    assert isinstance(candidate_circuit, QuantumCircuit)
    assert candidate_circuit.num_qubits == 5
    candidate_sv = Statevector.from_instruction(candidate_circuit)
    refrence_sv = Statevector.from_label("1".zfill(candidate_sv.num_qubits))
    assert candidate_sv.equiv(refrence_sv)
from qiskit.circuit import QuantumCircuit, Parameter
def create_parametrized_gate():
    """ Generate a 1 qubit QuantumCircuit with a parametrized Rx gate with parameter "theta".
    """
    theta = Parameter("theta")
    quantum_circuit = QuantumCircuit(1)
    quantum_circuit.rx(theta, 0)
    return quantum_circuit


def check(candidate):
    circuit = candidate()
    assert circuit.num_qubits == 1
    assert circuit.data[0].operation.name == "rx"
    assert circuit.data[0].operation.params[0].name == "theta"
from qiskit.circuit import QuantumCircuit, Parameter
def rx_gate(value=None):
    """ Return a 1-qubit QuantumCircuit with a parametrized Rx gate and parameter "theta". If value is not None, return the circuit with value assigned to theta.
    """
    theta = Parameter("theta")
    quantum_circuit = QuantumCircuit(1)
    quantum_circuit.rx(theta, 0)
    if value is not None:
        return quantum_circuit.assign_parameters({theta: value})
    return quantum_circuit


def check(candidate):
    from qiskit.quantum_info import Operator
    import math

    circuit = candidate()
    assert circuit.num_qubits == 1
    assert circuit.data[0].operation.name == "rx"
    assert circuit.data[0].operation.params[0].name == "theta"

    candidate_circuit = candidate(value=math.pi * 3 / 4)
    solution_circuit = QuantumCircuit(1)
    solution_circuit.rx((math.pi * 3 / 4), 0)
    assert Operator(solution_circuit).equiv(Operator(candidate_circuit))
from qiskit.circuit.library import EfficientSU2
def create_efficientSU2():
    """ Generate an EfficientSU2 circuit with 3 qubits, 1 reps and make insert_barriers true.
    """
    circuit = EfficientSU2(num_qubits=3, reps=1, insert_barriers=True)
    return circuit


def check(candidate):
    result = candidate()
    solution = EfficientSU2(num_qubits=3, reps=1, insert_barriers=True)
    assert isinstance(solution, EfficientSU2)
    assert solution.reps == result.reps
    assert solution.num_qubits == result.num_qubits
from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info.operators import Operator
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def create_operator() -> QuantumCircuit:
    """ Create a Qiskit circuit with the following unitary [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]], consisting of only single-qubit gates and CX gates, then transpile the circuit using pass manager with optimization level as 1.
    """
    XX = Operator([[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]])
    circ = QuantumCircuit(2, 2)
    circ.append(XX, [0, 1])
    pass_manager = generate_preset_pass_manager(optimization_level=1, basis_gates=["u", "cx"])
    return pass_manager.run(circ)


def check(candidate):
    result = candidate()
    XX = Operator([[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]])
    assert XX.equiv(Operator(result))
    for inst in result.data:
        if inst.operation.num_qubits > 1:
            assert inst.operation.name in ["cx", "barrier"]
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def get_statevector(circuit: QuantumCircuit) -> Statevector:
    """ Return the statevector from a circuit.
    """
    sv = Statevector.from_instruction(circuit)
    return sv


def check(candidate):
    test_circuit = QuantumCircuit(2)
    test_circuit.u(0.39702, 0.238798, 0.298374, 0)
    test_circuit.cx(0, 1)

    result = candidate(test_circuit)
    assert isinstance(result, Statevector)
    assert Statevector.from_instruction(test_circuit).equiv(result)
from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
def get_unitary() -> Operator:
    """ Get unitary matrix for a phi plus bell circuit and return it.
    """
    circ = QuantumCircuit(2)
    circ.h(0)
    circ.cx(0, 1)
    return Operator.from_circuit(circ).to_matrix()

def check(candidate):
    result = candidate()
    solution = QuantumCircuit(2)
    solution.h(0)
    solution.cx(0, 1)
    assert Operator(solution).equiv(result)
from qiskit import QuantumCircuit
import numpy as np
def custom_rotation_gate() -> QuantumCircuit:
    """ Create a quantum circuit that carries out a custom single-qubit rotation gate (U gate) with angles theta, phi and lambda all equal to pi/2.
    """
    circuit = QuantumCircuit(1)
    circuit.u(np.pi / 2, np.pi / 2, np.pi / 2, 0)
    return circuit


def check(candidate):
    from qiskit.quantum_info import Operator

    result = candidate()
    assert isinstance(result, QuantumCircuit)
    solution = QuantumCircuit(1)
    solution.u(np.pi / 2, np.pi / 2, np.pi / 2, 0)
    assert Operator(solution).equiv(Operator(result))
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def bell_each_shot() -> list[str]:
    """ Run a phi plus Bell circuit using Qiskit Sampler with the Aer simulator as backend for 10 shots and return measurement results for each shots. To do so, transpile the circuit using a pass manager with optimization level as 1.
    """
    bell = QuantumCircuit(2)
    # Apply gates
    bell.h(0)
    bell.cx(0, 1)
    bell.measure_all()

    # choose simulator backend
    backend = AerSimulator()
    # Transpile for simulator
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend)
    bell_circ = pass_manager.run(bell)
    sampler = Sampler(mode=backend)
    result = sampler.run([bell_circ],shots=10).result()
    memory = result[0].data.meas.get_bitstrings()
    return memory


def check(candidate):
    result = candidate()
    assert isinstance(result, list)
    assert len(result) > 0
    assert set(result) == {"00", "11"}
from qiskit_ibm_runtime.fake_provider import FakeBelemV2
from qiskit_ibm_runtime import Sampler
from qiskit_aer import AerSimulator
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def noisy_bell():
    """ Transpile a bell circuit using pass manager with optimization level as 1, run it using Qiskit Sampler with the Aer simulator as backend and get the execution counts.
    """
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0, 1)
    bell.measure_all()
    device_backend = FakeBelemV2()
    simulator = AerSimulator.from_backend(device_backend)
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=simulator)
    bell_circ = pass_manager.run(bell)
    sampler = Sampler(mode=simulator)
    result = sampler.run([bell_circ], shots=1000).result()
    counts = result[0].data.meas.get_counts()
    return counts


def check(candidate):
    result = candidate()
    assert isinstance(result, dict)
    assert (result["00"] + result["11"]) != sum(result.values())
from qiskit_ibm_runtime.fake_provider import FakeCairoV2
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_circuit(circuit: QuantumCircuit) -> QuantumCircuit:
    """ For the given Quantum Circuit, return the transpiled circuit for the Fake Cairo V2 backend using pass manager with optimization level as 1.
    """
    backend = FakeCairoV2()
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend)
    return pass_manager.run(circuit)


def check(candidate):
    backend = FakeCairoV2()
    circuit = QuantumCircuit(4, 3)
    circuit.cx([0, 1, 2, 3], [1, 2, 3, 0])
    t_circuit = candidate(circuit)
    assert t_circuit.num_qubits == backend.num_qubits
    for inst in t_circuit.data:
        assert inst.operation.name in backend.configuration().basis_gates
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates.equivalence_library import ( StandardEquivalenceLibrary as std_eqlib, )
from qiskit.transpiler.passes import BasisTranslator
from qiskit.transpiler import PassManager
import numpy as np
def unroll_circuit(circuit: QuantumCircuit) -> QuantumCircuit:
    """ Unroll circuit for the gateset: CX, ID, RZ, SX, X, U.
    """
    pass_ = BasisTranslator(std_eqlib, ["cx", "id", "rz", "sx", "x", "u"])
    pm = PassManager(pass_)
    return pm.run(circuit)


def check(candidate):
    from qiskit.quantum_info import Operator
    trial_circuit = QuantumCircuit(2)
    trial_circuit.h(0)
    trial_circuit.u(0.3, 0.1, 0.1, 1)
    trial_circuit.cp(np.pi / 4, 0, 1)
    trial_circuit.h(0)
    output = candidate(trial_circuit)
    assert Operator(output).equiv(Operator(trial_circuit))
    for inst in output.data:
        assert inst.operation.name in ["cx", "id", "rz", "sx", "x", "u"]
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeSydneyV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_circuit_noopt() -> QuantumCircuit:
    """ Transpile a 10-qubit GHZ circuit for the Fake Sydney V2 backend using pass manager with no optimization.
    """
    backend = FakeSydneyV2()
    ghz = QuantumCircuit(10)
    ghz.h(0)
    ghz.cx(0, range(1, 10))
    ghz.measure_all()
    pass_manager = generate_preset_pass_manager(optimization_level=0, backend=backend)
    return pass_manager.run(ghz)


def check(candidate):
    result = candidate()
    backend = FakeSydneyV2()
    # Optimization level 0 should use trivial qubit mapping
    # i.e. circuit qubit 'i' => device qubit 'i'.
    # This is very unlikely with higher optimization levels
    assert result.layout.initial_index_layout() == list(range(backend.num_qubits))
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeTorontoV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_circuit_maxopt() -> QuantumCircuit:
    """ Transpile and map an 11-qubit GHZ circuit for the Fake Toronto V2 backend using pass manager with maximum transpiler optimization.
    """
    backend = FakeTorontoV2()
    ghz = QuantumCircuit(11, 11)
    ghz.h(0)
    ghz.cx(0, range(1, 11))
    ghz.barrier()
    pass_manager = generate_preset_pass_manager(optimization_level=3, backend=backend)
    return pass_manager.run(ghz)


def check(candidate):
    result = candidate()
    result.remove_final_measurements()
    backend = FakeTorontoV2()
    # Check initial layout is not the trivial layout (this is very unlikely
    # if transpiled with optimization level 3)
    assert result.layout.initial_index_layout() != list(range(backend.num_qubits))
    # Optimization level 3 should easily find circuits with depth < 200
    assert result.depth() < 150
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakePerth
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_ghz_customlayout() -> QuantumCircuit:
    """ Using a pass manager with optimization level as 1, transpile and map a three-qubit GHZ circuit for the Fake Perth backend using custom initial layout: [2,4,6].
    """
    backend = FakePerth()
    ghz = QuantumCircuit(3)
    ghz.h(0)
    ghz.cx(0, [1, 2])
    ghz.barrier()
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend, initial_layout=[2, 4, 6])
    return pass_manager.run(ghz)


def check(candidate):
    result = candidate()
    result.remove_final_measurements()
    backend = FakePerth()
    assert result.num_qubits == backend.num_qubits
    assert result.layout.initial_index_layout()[:3] == [2, 4, 6]
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeOslo
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_circuit_dense() -> QuantumCircuit:
    """ Using a pass manager with optimization level as 1 and dense layout method, transpile and map a bell circuit for the Fake Oslo backend.
    """
    backend = FakeOslo()
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0, 1)
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend, layout_method="dense")
    solution_circ = pass_manager.run(bell)
    return solution_circ


def check(candidate):
    result = candidate()
    backend = FakeOslo()
    assert result.num_qubits == backend.num_qubits
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeAuckland
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def transpile_circuit_alap() -> QuantumCircuit:
    """ Using a pass manager with optimization level as 1 and as-late-as-possible scheduling method, transpile and map a bell circuit for the Fake Auckland backend. Return the circuit.
    """
    backend = FakeAuckland()
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0, 1)
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend, scheduling_method="alap")
    return pass_manager.run(bell)


def check(candidate):
    result = candidate()
    backend = FakeAuckland()
    assert result.num_qubits == backend.num_qubits
from qiskit import QuantumCircuit
def dj_constant_oracle() -> QuantumCircuit:
    """ Create a constant oracle for use in a Deutsch-Jozsa experiment. The oracle takes two input bits (qubits 0 and 1) and writes to one output bit (qubit 2).
    """
    oracle = QuantumCircuit(3)
    oracle.x(2)
    return oracle


def check(candidate):
    from qiskit.quantum_info import Operator

    qc = QuantumCircuit(3)
    constant_0_oracle = Operator(qc)
    qc.x(2)
    constant_1_oracle = Operator(qc)
    result = Operator(candidate())
    assert result.equiv(constant_0_oracle) or result.equiv(constant_1_oracle)
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
from numpy import isclose
def dj_algorithm(oracle: QuantumCircuit) -> bool:
    """ Given a Deutsch-Jozsa oracle in which the final qubit is the "output" qubit, return True if the oracle is constant or False otherwise.
    """
    n = oracle.num_qubits
    qc = QuantumCircuit(n, n - 1)
    qc.x(n - 1)
    qc.h(range(n))
    qc.compose(oracle, inplace=True)
    qc.h(range(n))
    qc.measure(range(n - 1), range(n - 1))
    counts = StatevectorSampler().run([qc]).result()[0].data.c.get_counts()
    return isclose(counts.get('00000000', 0), 1024)


def check(candidate):
    balanced = QuantumCircuit(5)
    balanced.cx(3, 4)
    assert candidate(balanced) == False
    constant = QuantumCircuit(9)
    constant.x(8)
    assert candidate(constant) == True
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passes import LookaheadSwap
from qiskit.transpiler.passmanager import PassManager
def passmanager_Lookahead(coupling) -> QuantumCircuit:
    """ Transpile a 7-qubit GHZ circuit using LookaheadSwap pass and an input custom coupling map [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]].
    """
    ghz = QuantumCircuit(7)
    ghz.h(0)
    ghz.cx(0, range(1, 7))
    coupling_map = CouplingMap(couplinglist=coupling)
    ls = LookaheadSwap(coupling_map=coupling_map)
    pass_manager = PassManager(ls)
    lookahead_circ = pass_manager.run(ghz)
    return lookahead_circ


def check(candidate):
    from qiskit.quantum_info import Statevector
    from qiskit.transpiler.passes import CheckMap
    from qiskit.converters import circuit_to_dag
    coupling = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
    coupling_map = CouplingMap(couplinglist=coupling)
    result = candidate(coupling)
    chkmp = CheckMap(coupling_map)
    chkmp.run(circuit_to_dag(result))
    assert chkmp.property_set["is_swap_mapped"] == True
    solution = QuantumCircuit(7)
    solution.h(0)
    solution.cx(0, range(1, 7))
    ls = LookaheadSwap(coupling_map=coupling_map)
    pass_manager = PassManager(ls)
    lookahead_circ = pass_manager.run(solution)
    assert Statevector.from_instruction(lookahead_circ).equiv(Statevector.from_instruction(result))
from qiskit.dagcircuit import DAGCircuit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.converters import circuit_to_dag
def bell_dag() -> DAGCircuit:
    """ Construct a DAG circuit for a 3-qubit Quantum Circuit with the bell state applied on qubit 0 and 1. Finally return the DAG Circuit object.
    """
    q = QuantumRegister(3, 'q')
    c = ClassicalRegister(3, 'c')
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    circ.measure(q[0], c[0])
    dag = circuit_to_dag(circ)
    return dag


def check(candidate):
    result = candidate()
    assert type(result) == DAGCircuit
    assert result.num_qubits() == 3
    assert result.depth() == 3
    assert dict(result.count_ops()) == {'h': 1, 'cx': 1, 'measure':1}
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library import HGate
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
def apply_op_back() -> DAGCircuit:
    """ Generate a DAG circuit for 3-qubit Quantum Circuit which consists of H gate on qubit 0 and CX gate on qubit 0 and 1. After converting the circuit to DAG, apply a Hadamard operation to the back of qubit 0 and return the DAGCircuit.
    """
    q = QuantumRegister(3, "q")
    c = ClassicalRegister(3, "c")
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    dag = circuit_to_dag(circ)
    dag.apply_operation_back(HGate(), qargs=[q[0]])
    return dag


def check(candidate):
    from qiskit.quantum_info import Statevector
    from qiskit.converters import dag_to_circuit
    result = candidate()
    assert type(result) == DAGCircuit
    assert result.num_qubits() == 3
    last_node = result.op_nodes()[-1]
    assert last_node.name == "h"
    assert len(result.descendants(last_node)) == 1
    q = QuantumRegister(3, "q")
    c = ClassicalRegister(3, "c")
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    circ.h(0)

    candidate_circ = dag_to_circuit(result)
    assert Statevector.from_instruction(circ).equiv(Statevector.from_instruction(candidate_circ))
from matplotlib.figure import Figure
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.visualization import plot_histogram
def visualize_bell_states()->Figure:
    """ Prepare phi plus and phi minus bell states and visualize their results in a histogram and return the histogram.
    """
    phi_plus = QuantumCircuit(2)
    phi_minus = QuantumCircuit(2)
    phi_plus.h(0)
    phi_plus.cx(0,1)
    phi_minus.x(0)
    phi_minus.h(0)
    phi_minus.cx(0,1)
    phi_plus.measure_all()
    phi_minus.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result_phi_plus = sampler.run([phi_plus], shots=1000).result()
    result_phi_minus = sampler.run([phi_minus], shots=1000).result()
    phi_plus_counts = result_phi_plus[0].data.meas.get_counts()
    phi_minus_counts = result_phi_minus[0].data.meas.get_counts()
    return plot_histogram([phi_plus_counts, phi_minus_counts], legend = ['|Φ+⟩ Count', '|Φ-⟩ Count'])


def check(candidate):
    from matplotlib.patches import Rectangle
    result = candidate()
    assert isinstance(result, Figure)
    gca = result.gca()
    assert {xlabel.get_text() for xlabel in gca.get_xticklabels()} == {"00", "11"}
    objs = gca.findobj(Rectangle)
    assert len(objs) >= 4
    counts = [obj.get_height() for obj in objs[:4]]
    shots = counts[0] + counts[1]
    for i in range(4):
        assert round(counts[i]/shots, 1) == 0.5