Skip to content

Commit

Permalink
Merge pull request oqc-community#114 from oqc-community/bugfix/he/cha…
Browse files Browse the repository at this point in the history
…nnel_full_id

Bug fix - Compare method calls instead of methods themselves
  • Loading branch information
hamidelmaazouz authored Jun 20, 2024
2 parents 016d767 + 803980d commit bc442d1
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 47 deletions.
2 changes: 1 addition & 1 deletion partials/minimal/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qat-compiler-minimal"
version = "1.1.0"
version = "1.1.1"
description = "A minimal version of the `qat-compiler` package."
readme = "README.rst"
documentation = "https://oqc-community.github.io/qat"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "qat-compiler"
# This name has the -compiler suffix in order to use the poetry and twine tools to build and publish to PyPI
# witout having to manually adjust the dist file names.
version = "1.1.0"
version = "1.1.1"
description = "A low-level quantum compiler and runtime which facilitates executing quantum IRs."
readme = "README.rst"
documentation = "https://oqc-community.github.io/qat"
Expand Down
2 changes: 1 addition & 1 deletion src/QAT/qat/purr/compiler/hardware_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_cl2qu_index_mapping(instructions: List[Instruction], model: QuantumHardw

qubit = next((
qubit for qubit in model.qubits
if qubit.get_acquire_channel().full_id == instruction.channel.full_id
if qubit.get_acquire_channel().full_id() == instruction.channel.full_id()
),
None)
if qubit is None:
Expand Down
29 changes: 23 additions & 6 deletions src/QAT/qat/purr/compiler/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
CompilerConfig,
MetricsType,
ResultsFormatting,
ErrorMitigationConfig,
)
from qat.purr.compiler.error_mitigation.readout_mitigation import get_readout_mitigation
from qat.purr.compiler.execution import (
InstructionExecutionEngine,
QuantumExecutionEngine,
_binary,
)
from qat.purr.compiler.hardware_models import QuantumHardwareModel, get_cl2qu_index_mapping
from qat.purr.compiler.hardware_models import (
QuantumHardwareModel,
get_cl2qu_index_mapping,
)
from qat.purr.compiler.instructions import Instruction, Repeat, is_generated_name
from qat.purr.compiler.interrupt import Interrupt, NullInterrupt
from qat.purr.compiler.metrics import CompilationMetrics, MetricsMixin
Expand Down Expand Up @@ -146,7 +150,7 @@ def squash_binary(value):
return results

def _apply_error_mitigation(self, results, instructions, error_mitigation):
if error_mitigation is None:
if error_mitigation is None or error_mitigation == ErrorMitigationConfig.Empty:
return results

# TODO: add support for multiple registers
Expand Down Expand Up @@ -181,7 +185,12 @@ def run_quantum_executable(
exe.run(self)

def _common_execute(
self, fexecute: callable, instructions, results_format=None, repeats=None, error_mitigation=None
self,
fexecute: callable,
instructions,
results_format=None,
repeats=None,
error_mitigation=None,
):
"""
Executes these instructions against the current engine and returns the results.
Expand Down Expand Up @@ -219,19 +228,27 @@ def _execute_with_interrupt(
"""
Executes these instructions against the current engine and returns the results.
"""

def fexecute(instrs):
return self.engine._execute_with_interrupt(instrs, interrupt)

return self._common_execute(fexecute, instructions, results_format, repeats, error_mitigation)
return self._common_execute(
fexecute, instructions, results_format, repeats, error_mitigation
)

def execute(self, instructions, results_format=None, repeats=None, error_mitigation=None):
def execute(
self, instructions, results_format=None, repeats=None, error_mitigation=None
):
"""
Executes these instructions against the current engine and returns the results.
"""

def fexecute(instrs):
return self.engine.execute(instrs)

return self._common_execute(fexecute, instructions, results_format, repeats, error_mitigation)
return self._common_execute(
fexecute, instructions, results_format, repeats, error_mitigation
)


def _binary_count(results_list, repeats):
Expand Down
26 changes: 18 additions & 8 deletions src/tests/test_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,14 @@ def test_basic_single_measures(self):
# correctly assigned, aka that measuring c[0] then c[1] results in c = [c0, c1].
assert len(results["c"]) == 2

@pytest.mark.parametrize("use_experimental,frontend_mod",
[(True, experimental_frontends),
(False, core_frontends),
], ids=("Experimental", "Standard"))
@pytest.mark.parametrize(
"use_experimental,frontend_mod",
[
(True, experimental_frontends),
(False, core_frontends),
],
ids=("Experimental", "Standard"),
)
def test_frontend_peek(self, use_experimental, frontend_mod):
with pytest.raises(ValueError):
fetch_frontend("", use_experimental=use_experimental)
Expand Down Expand Up @@ -961,7 +965,6 @@ def test_ecr_intrinsic(self):
def test_ecr_already_exists(self):
Qasm2Parser().parse(get_builder(self.echo), get_qasm2("ecr_exists.qasm"))


@pytest.mark.parametrize(
"qasm_file",
[
Expand Down Expand Up @@ -990,7 +993,9 @@ class TestQatOptimization:
def _measure_merge_timings(self, file, qubit_count, keys, expected):
builder = parse_and_apply_optimiziations(file, qubit_count=qubit_count)
qat_file = InstructionEmitter().emit(builder.instructions, builder.model)
timeline = EchoEngine(builder.model).create_duration_timeline(qat_file.instructions)
timeline = EchoEngine(builder.model).create_duration_timeline(
qat_file.instructions
)

def get_start_end(key, instruction, channel_type):
pulse_channel = builder.model.get_pulse_channel_from_device(
Expand Down Expand Up @@ -1303,6 +1308,7 @@ def test_simple_circuit(self):
counts = result.get_counts()
assert counts["1"] > 900


mapping_setup1 = (
"""
OPENQASM 2.0;
Expand Down Expand Up @@ -1345,6 +1351,10 @@ def test_cl2qu_index_mapping(qasm_string, expected_mapping):
hw = get_default_echo_hardware(3)
parser = Qasm2Parser()
result = parser.parse(get_builder(hw), qasm_string)
instructions = result.instructions
mapping = get_cl2qu_index_mapping(instructions, hw)
mapping = get_cl2qu_index_mapping(result.instructions, hw)
assert mapping == expected_mapping

blob = result.serialize()
result2 = InstructionBuilder.deserialize(blob)
mapping = get_cl2qu_index_mapping(result2.instructions, hw)
assert mapping == expected_mapping
Loading

0 comments on commit bc442d1

Please sign in to comment.