Qiskit/qiskit_humaneval huggingface dataset:
from matplotlib.figure import Figure
from qiskit.visualization import plot_circuit_layout
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def plot_circuit_layout_bell() -> Figure:
    """ Plot a circuit layout visualization for a transpiled bell circuit using a pass manager with optimization level as 1 for the Fake Athens V2 backend.
    """
    backend = FakeAthensV2()
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0,1)
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend)
    brisbane_bell = pass_manager.run(bell)
    return (plot_circuit_layout(brisbane_bell, backend))


def check(candidate):
    result = candidate()
    assert type(result) == Figure
from qiskit import QuantumCircuit
from matplotlib.figure import Figure
from qiskit.visualization import plot_state_city
from qiskit.quantum_info import Statevector
def plot_circuit_layout_bell() -> Figure:
    """ Plot a city_state for a bell circuit.
    """
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0,1)
    bell_state = Statevector(bell)
    plot_state_city(bell_state)
    return plot_state_city(bell_state)


def check(candidate):
    result = candidate()
    assert type(result) == Figure
    assert len(result.axes) == 2
from typing import Dict
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions
def sampler_qiskit() -> Dict:
    """ Run a Bell circuit on Qiskit Sampler and run the circuit on the Aer simulator with the seed set as 42. Return the resulting counts dictionary.
    """
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0,1)
    qc.measure_all()

    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=AerSimulator(), options=options)
    job = sampler.run([qc])
    result = job.result()[0].data.meas.get_counts()
    return result


def check(candidate):
    result = candidate()
    assert result == {"00": 521, "11": 503}
from numpy import float64
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Estimator
from qiskit.quantum_info import SparsePauliOp
def estimator_qiskit() -> float64:
    """ Run a Bell circuit on Qiskit Estimator and return expectation values for the bases II, XX, YY, ZZ.
    """
    observable = SparsePauliOp(["II","XX","YY","ZZ"], coeffs=[1, 1, -1, 1])
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0,1)

    estimator = Estimator(mode=AerSimulator())
    job = estimator.run([(qc, observable)])
    result = job.result()[0].data.evs.item()
    return result


def check(candidate):
    result = candidate()
    assert result == 4.0
from typing import List
from qiskit.circuit.random import random_circuit
from qiskit_ibm_runtime import Sampler, SamplerOptions
from qiskit_aer import AerSimulator
def run_multiple_sampler() -> List:
    """ Generate two random quantum circuits, each with 2 qubits and a depth of 2, using seed values of 0 and 1 respectively. Run the circuits using the Sampler on the Aer simulator with the seed set as 42 and return the counts for both circuits.
    """
    circuits = (
        random_circuit(2, 2, seed=0, measure=True).decompose(reps=1),
        random_circuit(2, 2, seed=1, measure=True).decompose(reps=1),
    )
    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=AerSimulator(), options=options)
    job = sampler.run(circuits)
    results = job.result()
    statevectors = [result.data.c.get_counts() for result in results]
    return statevectors


def check(candidate):
    result = candidate()
    assert isinstance(result, list)
    assert result == [{"01": 1024}, {"00": 552, "01": 472}]
from typing import Dict, Optional, Tuple
from qiskit_ibm_runtime import Batch, Sampler
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeCairoV2
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def run_jobs_on_batch() -> Tuple[Dict[str, PrimitiveJob], Optional[str]]:
    """ Generate all four Bell states and execute them on the Fake Cairo V2 backend using SamplerV2 with batch mode. Each Bell state circuit will be transpiled with an optimization level of 3, with the seed 123 for the transpiler.
    Returns a dictionary where the keys are the Bell state names ['phi_plus', 'phi_minus', 'psi_plus', 'psi_minus'] and the values are the corresponding RuntimeJob objects and the batch id.
    """
    def create_bell_circuit(state):
        "Helper function to create bell state"
        qc = QuantumCircuit(2)
        qc.h(0) 
        qc.cx(0, 1)
        if state == "phi_minus":
            qc.z(0)
        elif state == "psi_plus":
            qc.x(1)
        elif state == "psi_minus'":
            qc.x(1)
            qc.z(0)
        qc.measure_all()
        return qc
        
    # Create bell states
    bell_states = ["phi_plus", "phi_minus", "psi_plus", "psi_minus"]
    circuits = [create_bell_circuit(state) for state in bell_states]

    # Setting backend and pass managers
    backend = FakeCairoV2()
    pm = generate_preset_pass_manager(optimization_level = 3, backend=backend, seed_transpiler=123)

    # Running jobs using batch
    with Batch(backend=backend) as batch:
        jobs = {}
        sampler = Sampler(mode=batch)
        for bell_state, bell_circuit in zip(bell_states, circuits):
            isa_bell_circuit = pm.run(bell_circuit)
            jobs[bell_state] = sampler.run([(isa_bell_circuit)])
        return jobs


def check(candidate):
    from numpy import isclose
    jobs = candidate()
    reference_data = {
        'phi_plus': {'00': 0.10, '11': 0.10},
        'phi_minus': {'00': 0.10, '11': 0.10},
        'psi_plus': {'01': 0.10, '10': 0.10},
        'psi_minus': {'01': 0.001, '10': 0.002}
    }
    assert isinstance(jobs, dict)
    assert set(jobs.keys()) == set(reference_data.keys())
    for state, job in jobs.items():
        assert isinstance(job, PrimitiveJob)
        assert job.job_id() is not None
        counts = job.result()[0].data.meas.get_counts()
        shots = 4096
        normalized_counts = {k: v/shots for k, v in counts.items()}
        for key, value in reference_data[state].items():
            assert isclose(normalized_counts[key], value, atol=1e-01)
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
import numpy as np
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator, EstimatorOptions
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeCairoV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

def run_circuit_with_dd_trex() -> PrimitiveJob:
    """
    Run an EfficientSU2 circuit with 5 qubits, 2 repetitions, and pairwise entanglement on the Fake Cairo V2 backend.
    The circuit should be transpiled with an optimization level of 1 and a transpiler seed of 789. Use 1*Z_-1 observable to calculate the expectation value.
    """
    n_qubits = 5
    reps = 2
    circuit = EfficientSU2(n_qubits, entanglement="pairwise", reps=reps)
    observable = SparsePauliOp.from_sparse_list([("Z", [-1], 1.0)], num_qubits=n_qubits)
    

    # Generate random parameters
    rng = np.random.default_rng(1234)
    params = rng.uniform(-np.pi, np.pi, size=circuit.num_parameters)
    backend = FakeCairoV2()
    pm = generate_preset_pass_manager(optimization_level = 1, backend=backend, seed_transpiler=789)
    isa_circuit = pm.run(circuit)
    isa_observable = observable.apply_layout(isa_circuit.layout)

    options = EstimatorOptions()
    options.environment.job_tags = ["run_circ_dd_trex"]
    estimator = Estimator(mode=backend, options=options)
    job = estimator.run([(isa_circuit, isa_observable, params)])
    return job


def check(candidate):
    from numpy import isclose
    job = candidate()
    assert isinstance(job, PrimitiveJob)
    assert job.job_id() is not None
    result = job.result()
    assert isclose(result[0].data.evs.item(), 0.33, atol=0.06)
from qiskit import QuantumCircuit
def bv_function(s: str) -> QuantumCircuit:
    """ Write a function to design a Bernstein-Vazirani oracle from a bitstring and return it.
    """
    n = len(s)
    qc = QuantumCircuit(n + 1)
    for index, bit in enumerate(reversed(s)):
        if bit == "1":
            qc.cx(index, n)
    return qc


def check(candidate):
    from qiskit.quantum_info.operators import Operator
    s = "1111"
    result = candidate(s)
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 5
    solution = QuantumCircuit(5)
    for i in range(4):
        solution.cx(i, 4)
    assert Operator(result).equiv(Operator(solution))
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.primitives.containers.primitive_result import PrimitiveResult
def bv_algorithm(s: str) -> [list, PrimitiveResult]:
    """ Illustrate a Bernstein-Vazirani algorithm routine on Qiskit and run it using Qiskit Sampler with Aer simulator as backend for a string of 0s and 1s. Return the bit strings of the result and the result itself.
    """
    qc = QuantumCircuit(len(s) + 1)
    for index, bit in enumerate(reversed(s)):
        if bit == "1":
            qc.cx(index, len(s))
    qc.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result= sampler.run([qc], shots=1).result()
    bitstrings = result[0].data.meas.get_bitstrings()
    return [bitstrings, result]


def check(candidate):
    s = "1111"
    result = candidate(s)
    assert (type(result[0]) == list)
    assert (len(result[0]) == result[1][0].data.meas.num_shots)
    assert (type(result[1]) == PrimitiveResult)
from qiskit import QuantumCircuit
def create_quantum_circuit_based_h0_crz01_h1_cry10(theta):
    """ Build a 2-qubit Quantum Circuit composed by H gate in Quantum register 0, Controlled-RZ gate in quantum register 0 1 with given input theta value, H gate in quantum register 1 and Controlled-RY gate in quantum register 1 0 with given input theta value.
    """
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.crz(theta,0,1)
    qc.h(1)
    qc.cry(theta,1,0)
    return qc


def check(candidate):
    from qiskit import QuantumRegister
    from qiskit.circuit import CircuitInstruction
    from math import pi
    from qiskit.circuit.library import HGate, CRZGate, CRYGate
    qr = QuantumRegister(2, name="q")
    theta = pi/2
    data = candidate(theta).data
    assert data[0]==CircuitInstruction(HGate(), [qr[0]], [])
    assert data[1]==CircuitInstruction(CRZGate(theta), [qr[0], qr[1]], [])
    assert data[2]==CircuitInstruction(HGate(), [qr[1]], [])
    assert data[3]==CircuitInstruction(CRYGate(theta), [qr[1], qr[0]], [])
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def create_uniform_superposition(n: int) -> QuantumCircuit:
    """ Initialize a uniform superposition on n qubits and return statevector.
    """
    qc = QuantumCircuit(n)
    qc.h(range(n))
    return Statevector(qc)


def check(candidate):
    from qiskit.quantum_info import state_fidelity
    from math import sqrt
    assert round(state_fidelity(candidate(1), [1/sqrt(2)]*2),3)==1
    assert round(state_fidelity(candidate(2), [0.5]*4),3)==1
    assert round(state_fidelity(candidate(3), [1/sqrt(8)]*8),3)==1
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions
def init_random_3qubit(desired_vector: [complex])-> dict:
    """ Initialize a non-trivial 3-qubit state for a given desired vector state and return counts after running it using Qiskit Sampler with the Aer simulator as backend and ser=t seed as 42.
    """
    qc = QuantumCircuit(3)
    qc.initialize(desired_vector, range(3))
    qc.measure_all()
    backend = AerSimulator()
    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=backend,options=options)
    result = sampler.run([qc]).result()
    return result[0].data.meas.get_counts()


def check(candidate):
    from math import sqrt
    from qiskit.quantum_info import state_fidelity
    desired_vector = [0.25j, 1 /sqrt(8)+0j, 0.25+0.25j, 0, 0,1 / sqrt(8) * (1+2j), 0.25+0j, 0]
    result = candidate(desired_vector)
    assert isinstance(result, dict)
    assert result == {"101": 665, "010": 118, "000": 49, "110": 51, "001": 141}
from qiskit.quantum_info.operators import Operator, Pauli
import numpy as np
def compose_op() -> Operator:
    """ Compose XZ with a 3-qubit identity operator using the Operator and the Pauli 'YX' class in Qiskit. Return the operator instance.
    """
    op = Operator(np.eye(2 ** 3))
    YX = Operator(Pauli('YX'))
    op.compose(YX, qargs=[0, 2], front=True)
    return op


def check(candidate):
    result = candidate()
    op = Operator(np.eye(2 ** 3))
    YX = Operator(Pauli('YX'))
    op.compose(YX, qargs=[0, 2], front=True)
    assert(result == op)
from qiskit.quantum_info.operators import Operator, Pauli
def combine_op() -> Operator:
    """ Combine the following three operators XX YY ZZ as: 0.5 * (XX + YY - 3 * ZZ).
    """
    XX = Operator(Pauli('XX'))
    YY = Operator(Pauli('YY'))
    ZZ = Operator(Pauli('ZZ'))

    op = 0.5 * (XX + YY - 3 * ZZ)
    return op


def check(candidate):
    result = candidate()
    XX = Operator(Pauli('XX'))
    YY = Operator(Pauli('YY'))
    ZZ = Operator(Pauli('ZZ'))

    op = 0.5 * (XX + YY - 3 * ZZ)
    assert (result == op)
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit
def generate_pass_manager_obj()-> QuantumCircuit:
    """ Instantiate a preset_passmanager using Qiskit using the least busy device available and optimzation level 3. Return the resulting passmanager instance.
    """
    provider = QiskitRuntimeService()
    backend = provider.least_busy()
    pass_manager = generate_preset_pass_manager(optimization_level=3, backend=backend)
    return pass_manager


def check(candidate):
    from qiskit.transpiler.passmanager import StagedPassManager
    result = candidate()
    assert(type(result) == StagedPassManager)
from qiskit import QuantumCircuit
def tensor_circuits() -> QuantumCircuit:
    """ Write an example using Qiskit that performs tensor operation on a 1-qubit quantum circuit with an X gate and a 2-qubit quantum circuit with a CRY gate, where the CRY gate has an angle of 0.2 radians and is controlled by qubit 0.
    """
    top = QuantumCircuit(1)
    top.x(0)
    bottom = QuantumCircuit(2)
    bottom.cry(0.2, 0, 1)
    tensored = bottom.tensor(top)
    return tensored


def check(candidate):
    from qiskit.quantum_info import Statevector
    result = candidate()
    top = QuantumCircuit(1)
    top.x(0);
    bottom = QuantumCircuit(2)
    bottom.cry(0.2, 0, 1)
    tensored = bottom.tensor(top)
    assert Statevector.from_instruction(result).equiv(Statevector.from_instruction(tensored))
from qiskit.quantum_info.random import random_clifford
def get_random_clifford(n_qubits):
    """ Generate a random clifford circuit using the input n_qubit as number of qubits.
    """
    return random_clifford(num_qubits=n_qubits)


def check(candidate):
    from qiskit.quantum_info import Clifford
    result = candidate(3)
    assert result.num_qubits == 3
    assert isinstance(result, Clifford)
from qiskit.circuit.library import LinearFunction
from qiskit.synthesis.linear.linear_matrix_utils import random_invertible_binary_matrix
def get_random_linear_function(n_qubits, seed):
    """ Generate a random linear function circuit using the input parameters n_qubits and seed, and the random_invertible_binary_matrix method.
    """
    return LinearFunction(random_invertible_binary_matrix(num_qubits=n_qubits, seed=seed))


def check(candidate):
    result = candidate(3,3)
    assert result.num_qubits == 3
    assert isinstance(result, LinearFunction)
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def random_coin_flip(samples: int)->dict:
    """ Design a Quantum Circuit that simulates random coin flips for the given samples using Qiskit Sampler with the Aer simulator as backend and outputs the count of heads and tails in a dictionary. The heads should be stored in the dict as 'Heads' and tails as 'Tails'. For example
    random_coin_flip(10) == {'Heads' : 5, 'Tails : 5}
    random_coin_flip(20) == {'Heads' : 9, 'Tails : 11}.
    """
    circuit = QuantumCircuit(1,1)
    circuit.h(0)
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit], shots=samples).result()
    counts = result[0].data.meas.get_counts()
    return {'Heads' : counts['0'], 'Tails': counts['1']}


def check(candidate):
    samples = 2000
    result = candidate(samples)

    assert result.keys() == {'Heads', 'Tails'}
    assert round(result['Heads']/samples, 1) == 0.5
    assert round(result['Tails']/samples, 1) == 0.5
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def random_number_generator_unsigned_8bit(n: int)->[int]:
    """ Write a function that generates n number of random 8-bit unsigned integers using a Quantum Circuit and outputs a list of integers.
    """
    circuit = QuantumCircuit(8)
    circuit.h(range(8))
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit], shots=n).result()
    samples = result[0].data.meas.get_bitstrings()
    return [int(sample, 2) for sample in samples]


def check(candidate):
    result = candidate(10)
    assert isinstance(result, list)
    assert len(result) == 10
    for i in range(10):
        assert result[i] >= 0 and result[i] < 256
from qiskit import QuantumCircuit
def simple_elitzur_vaidman()->QuantumCircuit:
    """ Return a simple Elitzur Vaidman bomb tester circuit.
    """
    circuit = QuantumCircuit(2)
    circuit.h(0)
    circuit.cx(0,1)
    circuit.h(0)
    return circuit


def check(candidate):
    from qiskit.quantum_info import Statevector
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    circuit = QuantumCircuit(2)
    circuit.h(0)
    circuit.cx(0,1)
    circuit.h(0)
    assert Statevector.from_instruction(result).equiv(Statevector.from_instruction(circuit))
from qiskit import  QuantumCircuit
def remove_gate_in_position(circuit: QuantumCircuit, position: int):
    """ Remove the gate in the input position for the given Quantum Circuit.
    """
    del circuit.data[position]
    return circuit


def check(candidate):
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0, 1)
    qc.h(1)
    qc.h(0)
    expected_qc = QuantumCircuit(2)
    expected_qc.cx(0, 1)
    expected_qc.h(1)
    expected_qc.h(0)
    assert candidate(qc, 0)==expected_qc
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import Instruction
def quantum_teleportation_circuit(data: [Instruction])->QuantumCircuit:
    """ Write a function to build a quantum teleportation circuit that takes a list of instructions as an argument to transfer the data from the sender to the receiver while taking advantage of dynamic circuits.
    """
    sender = QuantumRegister(1, "sender")
    receiver = QuantumRegister(1, "receiver")
    ancillary = QuantumRegister(1, "ancillary")
    c_sender = ClassicalRegister(1, "c_sender")
    c_receiver = ClassicalRegister(1, "c_receiver")
    c_ancillary = ClassicalRegister(1, "c_ancillary")
    circuit = QuantumCircuit(sender, ancillary, receiver, c_sender, c_ancillary, c_receiver)
    for gate in data:
        circuit.append(gate, [0])
    circuit.barrier()
    circuit.h(ancillary)
    circuit.cx(ancillary, receiver)
    circuit.barrier()
    circuit.cx(sender, ancillary)
    circuit.h(sender)
    circuit.measure(sender, c_sender)
    circuit.measure(ancillary, c_ancillary)
    circuit.barrier()
    with circuit.if_test((c_ancillary, 1)):
        circuit.x(receiver)
    with circuit.if_test((c_sender, 1)):
        circuit.z(receiver)
    circuit.barrier()
    circuit.measure(receiver, c_receiver)
    return circuit


def check(candidate):
    from qiskit.circuit.library import XGate, HGate
    from qiskit_aer import AerSimulator
    from qiskit_ibm_runtime import Sampler
    from qiskit.result import marginal_distribution
    result_x = candidate([XGate()])
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    assert isinstance(result_x, QuantumCircuit)
    assert result_x.num_qubits == 3
    assert result_x.count_ops()['x'] == 1 and result_x.count_ops()['if_else'] == 2
    assert  marginal_distribution(sampler.run([result_x]).result()[0].data.c_receiver.get_counts()) == {'1': 1024}
    result_h = candidate([HGate()])
    assert result_h.count_ops()['h'] == 3 and result_h.count_ops()['if_else'] == 2
    assert round(marginal_distribution(sampler.run([result_h]).result()[0].data.c_receiver.get_counts())['0']/1024, 1) == 0.5
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
def send_bits(bitstring: str)->QuantumCircuit:
    """ Provide a quantum circuit that enables the transmission of two classical bits from the sender to the receiver through a single qubit of quantum communication, given that the sender and receiver have access to entangled qubits.
    """
    sender = QuantumRegister(1, "sender")
    receiver = QuantumRegister(1, "receiver")
    measure = ClassicalRegister(2, "measure")
    circuit = QuantumCircuit(sender, receiver, measure)
    # Prepare ebit used for superdense coding
    circuit.h(sender)
    circuit.cx(sender, receiver)
    circuit.barrier()
    # sender's operations
    if bitstring[1] == "1":
        circuit.z(sender)
    if bitstring[0] == "1":
        circuit.x(sender)
    circuit.barrier()
    # receiver's actions
    circuit.cx(sender, receiver)
    circuit.h(sender)
    circuit.measure(sender, measure[0])
    circuit.measure(receiver, measure[1])
    return circuit


def check(candidate):
    from qiskit_aer import AerSimulator
    from qiskit_ibm_runtime import Sampler
    result_1 = candidate("10")
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    assert isinstance(result_1, QuantumCircuit)
    assert result_1.num_qubits == 2
    assert result_1.count_ops()["x"] == 1
    assert sampler.run([result_1]).result()[0].data.measure.get_counts() == {"10": 1024}
    result_2 = candidate("01")
    assert result_2.depth() == 6
    assert result_2.count_ops()["z"] == 1
    assert sampler.run([result_2]).result()[0].data.measure.get_counts() == {"01": 1024}
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.circuit.library import XOR
def xor_gate(a: int, b: int)->dict:
    """ Given two 8-bit integers a and b design a Quantum Circuit that acts as a classical XOR gate. Simulate the circuit using Qiskit Sampler with the Aer simulator as backend and return the counts of the result.
    """
    circuit = XOR(8, a).compose(XOR(8, b))
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit.decompose()]).result()
    return result[0].data.meas.get_counts()


def check(candidate):
    assert candidate(10, 20) == {"00011110": 1024}
    assert candidate(61, 9) == {"00110100": 1024}
    assert candidate(47, 8) == {"00100111": 1024}