|
275 | 275 | "task_id": "qiskitHumanEval/34", |
276 | 276 | "prompt": "from typing import Dict, Optional, Tuple\nfrom qiskit_ibm_runtime import Batch, Sampler\nfrom qiskit.primitives.primitive_job import PrimitiveJob\nfrom qiskit_ibm_runtime.fake_provider import FakeAlgiers\nfrom qiskit.transpiler import CouplingMap\nfrom qiskit import QuantumCircuit\nfrom qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\ndef run_jobs_on_batch() -> Tuple[Dict[str, PrimitiveJob], Optional[str]]:\n \"\"\" Generate all four Bell states and execute them on the FakeAlgiers 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.\n 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.\n \"\"\"", |
277 | 277 | "canonical_solution": "\n def create_bell_circuit(state):\n \"Helper function to create bell state\"\n qc = QuantumCircuit(2)\n qc.h(0) \n qc.cx(0, 1)\n if state == \"phi_minus\":\n qc.z(0)\n elif state == \"psi_plus\":\n qc.x(1)\n elif state == \"psi_minus'\":\n qc.x(1)\n qc.z(0)\n qc.measure_all()\n return qc\n \n # Create bell states\n bell_states = [\"phi_plus\", \"phi_minus\", \"psi_plus\", \"psi_minus\"]\n circuits = [create_bell_circuit(state) for state in bell_states]\n\n # Setting backend and pass managers\n backend = FakeAlgiers()\n coupling_map = CouplingMap(backend.configuration().coupling_map)\n pm = generate_preset_pass_manager(optimization_level = 3, backend=backend, seed_transpiler=123, coupling_map=coupling_map)\n\n # Running jobs using batch\n with Batch(backend=backend) as batch:\n jobs = {}\n sampler = Sampler(mode=batch)\n for bell_state, bell_circuit in zip(bell_states, circuits):\n isa_bell_circuit = pm.run(bell_circuit)\n jobs[bell_state] = sampler.run([(isa_bell_circuit)])\n return jobs\n", |
278 | | - "test": "def check(candidate):\n from numpy import isclose\n jobs = candidate()\n reference_data = {\n 'phi_plus': {'00': 0.10, '11': 0.10},\n 'phi_minus': {'00': 0.10, '11': 0.10},\n 'psi_plus': {'01': 0.10, '10': 0.10},\n 'psi_minus': {'01': 0.1, '10': 0.2}\n }\n assert isinstance(jobs, dict)\n assert set(jobs.keys()) == set(reference_data.keys())\n for state, job in jobs.items():\n assert isinstance(job, PrimitiveJob)\n assert job.job_id() is not None\n counts = job.result()[0].data.meas.get_counts()\n shots = 4096\n normalized_counts = {k: v/shots for k, v in counts.items()}\n for key, value in reference_data[state].items():\n assert isclose(normalized_counts[key], value, atol=1e-01)\n", |
| 278 | + "test": "def check(candidate):\n from numpy import isclose\n jobs = candidate()\n reference_data = {\n 'phi_plus': {'00': 0.10, '11': 0.10},\n 'phi_minus': {'00': 0.10, '11': 0.10},\n 'psi_plus': {'01': 0.10, '10': 0.10},\n 'psi_minus': {'01': 0.1, '10': 0.10}\n }\n assert isinstance(jobs, dict)\n assert set(jobs.keys()) == set(reference_data.keys())\n for state, job in jobs.items():\n assert isinstance(job, PrimitiveJob)\n assert job.job_id() is not None\n counts = job.result()[0].data.meas.get_counts()\n shots = 4096\n normalized_counts = {k: v/shots for k, v in counts.items()}\n for key, value in reference_data[state].items():\n assert isclose(normalized_counts[key], value, atol=1e-01)\n", |
279 | 279 | "entry_point": "run_jobs_on_batch", |
280 | 280 | "difficulty_scale": "difficult" |
281 | 281 | }, |
|
673 | 673 | }, |
674 | 674 | { |
675 | 675 | "task_id": "qiskitHumanEval/84", |
676 | | - "prompt": "from qiskit import pulse\nfrom qiskit_ibm_runtime.fake_provider import FakeBelemV2\nfrom qiskit.pulse import DriveChannel, Gaussian\ndef define_gaussian_pulse_schedule():\n \"\"\" Using Qiskit Pulse, create a Gaussian pulse schedule on drive channel 0 with a duration of 128 and name this schedule 'gaussian_pulse_schedule'. Configure it for the FakeBelem backend and return the resulting pulse schedule.\n \"\"\"", |
677 | | - "canonical_solution": "\n backend = FakeBelemV2()\n gaussian_pulse = Gaussian(duration=128, amp=0.1, sigma=16)\n d0 = DriveChannel(0)\n with pulse.build(backend=backend, name='gaussian_pulse_schedule') as gaussian_pulse_schedule:\n pulse.play(gaussian_pulse, d0)\n return gaussian_pulse_schedule\n", |
678 | | - "test": "def check(candidate):\n gaussian_pulse_schedule = candidate()\n assert gaussian_pulse_schedule.name == 'gaussian_pulse_schedule'\n assert gaussian_pulse_schedule.duration == 128\n", |
679 | | - "entry_point": "define_gaussian_pulse_schedule", |
680 | | - "difficulty_scale": "intermediate" |
| 676 | + "prompt": "from qiskit import QuantumCircuit\nfrom qiskit.circuit.library import U3Gate\ndef controlled_custom_unitary_circuit():\n \"\"\" Create a 2-qubit quantum circuit where you define a custom 1-qubit unitary gate (e.g., U3) and apply it as a controlled gate with qubit 0 as control and qubit 1 as target. Return the final circuit.\n \"\"\"", |
| 677 | + "canonical_solution": "\n qc = QuantumCircuit(2)\n custom_gate = U3Gate(0.3, 0.2, 0.1).control()\n qc.append(custom_gate, [0, 1])\n return qc\n", |
| 678 | + "test": "def check(candidate):\n qc = candidate()\n assert isinstance(qc, QuantumCircuit)\n assert qc.num_qubits == 2\n assert any(instr[0].name.startswith('cu3') or 'u3' in instr[0].name for instr in qc.data)\n", |
| 679 | + "entry_point": "controlled_custom_unitary_circuit", |
| 680 | + "difficulty_scale": "basic" |
681 | 681 | }, |
682 | 682 | { |
683 | 683 | "task_id": "qiskitHumanEval/85", |
|
689 | 689 | }, |
690 | 690 | { |
691 | 691 | "task_id": "qiskitHumanEval/86", |
692 | | - "prompt": "from qiskit import pulse\nfrom qiskit_ibm_runtime.fake_provider import FakeBelemV2\nfrom qiskit.pulse import DriveChannel, Constant, Play, Delay\ndef pulse_schedule_with_constant_and_delay():\n \"\"\" Using Qiskit Pulse, create a schedule with a constant pulse on drive channel 0, featuring a duration of 160 and an amplitude of 0.1 and name this schedule \"pulse_schedule_with_constant_and_delay\". Use the FakeBelem backend for configuration. After creating the pulse, add a delay of 400 to the schedule, then replay the same pulse. Return the completed pulse schedule.\n \"\"\"", |
693 | | - "canonical_solution": "\n backend = FakeBelemV2()\n constant_pulse = Constant(duration=160, amp=0.1)\n drive_chan = DriveChannel(0)\n with pulse.build(backend=backend, name=\"pulse_schedule_with_constant_and_delay\") as pulse_sched:\n pulse.play(constant_pulse, drive_chan)\n pulse.delay(400, drive_chan)\n pulse.play(constant_pulse, drive_chan)\n return pulse_sched\n", |
694 | | - "test": "def check(candidate):\n pulse_sched = candidate()\n constant_pulses = 0\n delays = 0\n for _, inst in pulse_sched.instructions:\n if isinstance(inst, Play):\n if isinstance(inst.pulse, Constant):\n constant_pulses += 1\n elif isinstance(inst, Delay):\n delays += 1\n assert constant_pulses == 2, \"Schedule should contain exactly two Constant pulses.\"\n assert delays == 1, \"Schedule should contain exactly one Delay instruction.\"\n assert pulse_sched.name == \"pulse_schedule_with_constant_and_delay\"\n", |
695 | | - "entry_point": "pulse_schedule_with_constant_and_delay", |
| 692 | + "prompt": "from qiskit import QuantumCircuit\nfrom qiskit.transpiler.passes import CollectLinearFunctions\nfrom qiskit.transpiler import PassManager\ndef collect_linear_blocks_with_and_without_limit():\n \"\"\" Create a 5-qubit quantum circuit with a chain of CX gates and apply Qiskit's CollectLinearFunctions transpiler pass. Return two circuits:\n 1. One with no block width restriction.\n 2. One with a max_block_width of 3.\n Use PassManager to apply the pass and return both circuits.\n \"\"\"", |
| 693 | + "canonical_solution": "\n qc = QuantumCircuit(5)\n qc.h(0)\n qc.cx(0, 1)\n qc.cx(1, 2)\n qc.cx(2, 3)\n qc.cx(3, 4)\n pm_full = PassManager([CollectLinearFunctions()])\n full_block = pm_full.run(qc)\n pm_limited = PassManager([CollectLinearFunctions(max_block_width=3)])\n limited_block = pm_limited.run(qc)\n return full_block, limited_block\n", |
| 694 | + "test": "def check(candidate):\n from qiskit.circuit.library import LinearFunction\n full, limited = candidate()\n full_linear_count = sum(1 for instr in full.data if isinstance(instr.operation, LinearFunction))\n limited_linear_count = sum(1 for instr in limited.data if isinstance(instr.operation, LinearFunction))\n assert full_linear_count == 1\n assert limited_linear_count > 1\n", |
| 695 | + "entry_point": "collect_linear_blocks_with_and_without_limit", |
696 | 696 | "difficulty_scale": "intermediate" |
697 | 697 | }, |
698 | 698 | { |
|
835 | 835 | "task_id": "qiskitHumanEval/104", |
836 | 836 | "prompt": "from qiskit_ibm_runtime.fake_provider import FakeOsaka, FakeSherbrooke, FakeBrisbane\nfrom qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\nfrom qiskit.circuit.library import QFT\ndef backend_with_lowest_complexity():\n \"\"\" Transpile the 4-qubit QFT circuit using preset passmanager with optimization level 3 and seed transpiler = 1234 in FakeOsaka, FakeSherbrooke and FakeBrisbane. Compute the cost of the instructions by penalizing the two qubit gate with a cost of 5, rz gates with a cost 1 and other gates with a cost 2 and return the value of the highest cost among these backends.\n \"\"\"", |
837 | 837 | "canonical_solution": "\n qc = QFT(4)\n backends = [FakeOsaka(), FakeSherbrooke(), FakeBrisbane()]\n complexity_dict = {}\n for backend in backends:\n pm = generate_preset_pass_manager(\n optimization_level=3, seed_transpiler=1234, backend=backend\n )\n data = pm.run(qc).data\n complexity = 0\n for instruc in data:\n if instruc.operation.num_qubits == 2:\n complexity += 5\n elif instruc.operation.name == \"rz\":\n complexity += 1\n else:\n complexity += 2\n complexity_dict[backend.name] = complexity\n return complexity_dict[max(complexity_dict, key=complexity_dict.get)]\n", |
838 | | - "test": "def check(candidate):\n complexity_can = candidate()\n complexity_exp = 217\n assert complexity_can == complexity_exp\n", |
| 838 | + "test": "def check(candidate):\n complexity_can = candidate()\n complexity_exp = 194\n assert complexity_can == complexity_exp\n", |
839 | 839 | "entry_point": "backend_with_lowest_complexity", |
840 | 840 | "difficulty_scale": "intermediate" |
841 | 841 | }, |
|
1202 | 1202 | { |
1203 | 1203 | "task_id": "qiskitHumanEval/150", |
1204 | 1204 | "prompt": "from qiskit import QuantumCircuit\nfrom numpy import pi\ndef for_loop_circuit(qc: QuantumCircuit, n: int) -> QuantumCircuit:\n \"\"\" Add a sub-circuit to the quantum circuit `qc` that applies a series of operations for `n` iterations using the `for_loop`.\n\n In each iteration `i`, perform the following:\n 1. Apply a `RY` rotation on qubit 0 with an angle of `pi/n * i`.\n 2. Apply a Hadamard gate to qubit 0 and a CNOT gate between qubits 0 and 1 to create a phi plus Bell state.\n 3. Measure qubit 0 and store the result in the corresponding classical register.\n 4. Break the loop if the classical register for qubit 0 measures the value 1.\n\n Use the `for_loop` control flow structure to implement the loop and include conditional breaking based on the measurement.\n \"\"\"", |
1205 | | - "canonical_solution": "\n with qc.for_loop(range(n)) as i:\n qc.ry(pi/n*i, 0)\n qc.h(0)\n qc.cx(0, 1)\n qc.measure(0, 0)\n qc.break_loop().c_if(0, 1)\n return qc\n", |
1206 | | - "test": "def check(candidate):\n from qiskit.circuit.library import RYGate, HGate, CXGate, Measure\n from qiskit.circuit import BreakLoopOp, CircuitInstruction\n\n qc = QuantumCircuit(2,1)\n solution = candidate(qc, 2)\n \n assert len(solution.data) > 0, \"Circuit should have operations added\"\n \n op = solution.data[0].operation\n\n assert op.name == \"for_loop\"\n assert op.num_qubits == 2 and op.num_clbits == 1\n indexset, loop_param, sub_qc = op.params\n assert indexset == range(2)\n \n # Test sub circuit\n data = sub_qc.data\n qr = qc.qregs[0]\n cr = qc.cregs[0]\n assert data[0] == CircuitInstruction(RYGate(pi/2*loop_param), [qr[0]], [])\n assert data[1] == CircuitInstruction(HGate(), [qr[0]], [])\n assert data[2] == CircuitInstruction(CXGate(), [qr[0], qr[1]], [])\n assert data[3] == CircuitInstruction(Measure(), [qr[0]],[cr[0]])\n assert data[4] == CircuitInstruction(BreakLoopOp(2,1), [qr[0], qr[1]], [cr[0]]) or CircuitInstruction(BreakLoopOp(2,1), [qr[1], qr[0]], [cr[0]])\n", |
| 1205 | + "canonical_solution": "\n with qc.for_loop(range(n)) as i:\n qc.ry(pi/n*i, 0)\n qc.h(0)\n qc.cx(0, 1)\n qc.measure(0, 0)\n with qc.if_test((qc.clbits[0], 1)):\n qc.break_loop()\n return qc\n", |
| 1206 | + "test": "def check(candidate):\n from qiskit.circuit.library import RYGate, HGate, CXGate, Measure\n from qiskit.circuit.controlflow import IfElseOp\n from qiskit.circuit import CircuitInstruction\n\n qc = QuantumCircuit(2,1)\n solution = candidate(qc, 2)\n \n assert len(solution.data) > 0, \"Circuit should have operations added\"\n \n op = solution.data[0].operation\n\n assert op.name == \"for_loop\"\n assert op.num_qubits == 2 and op.num_clbits == 1\n indexset, loop_param, sub_qc = op.params\n assert indexset == range(2)\n \n # Test sub circuit\n data = sub_qc.data\n qr = qc.qregs[0]\n cr = qc.cregs[0]\n assert data[0] == CircuitInstruction(RYGate(pi/2*loop_param), [qr[0]], [])\n assert data[1] == CircuitInstruction(HGate(), [qr[0]], [])\n assert data[2] == CircuitInstruction(CXGate(), [qr[0], qr[1]], [])\n assert data[3] == CircuitInstruction(Measure(), [qr[0]],[cr[0]])\n assert isinstance(data[4].operation, IfElseOp)\n assert set(data[4].qubits) == {qr[0], qr[1]} or set(data[4].qubits) == {qr[1], qr[0]}\n assert [bit._index for bit in data[4].clbits] == [0]\n", |
1207 | 1207 | "entry_point": "for_loop_circuit", |
1208 | 1208 | "difficulty_scale": "difficult" |
1209 | 1209 | } |
|
0 commit comments