Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: [
ubuntu-latest, # Linux/x64
macos-13, # MacOS/x64
macos-15-intel, # MacOS/x64
windows-latest, # Windows/x64
ubuntu-24.04-arm, # Linux/ARM64
macos-14 # MacOS/ARM64
Expand All @@ -32,6 +32,7 @@ jobs:
run: |
python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT_LINUX: LIBQASM_CONAN_BUILD_PATTERNS="m4/* bison/* flex/*"
CIBW_BEFORE_ALL_LINUX: ${{ (matrix.os == 'ubuntu-24.04-arm') && 'yum install -y java-11-openjdk' || ':' }}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -85,7 +86,7 @@ jobs:
uses: actions/download-artifact@v4
id: download
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.12.4
uses: pypa/gh-action-pypi-publish@v1.13.0
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
with:
user: __token__
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

cpp-macos-x64:
name: "C++ tests (clang/MacOS/x64)"
runs-on: macos-13 # x64
runs-on: macos-15-intel # x64
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:

python-macos-x64:
name: "Python tests (macOS/x64)"
runs-on: macos-13
runs-on: macos-15-intel
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- **Fixed** for any bug fixes.
- **Removed** for now removed features.

## [ 1.3.0 ] - [ 2026-03-23 ]

### Added
- `U`, `Z90`, and `mZ90` unitary instructions.
- The `measure` instruction also accepts (3 float) parameters to specify measurement axis.


## [ 1.2.1 ] - [ 2025-07-28 ]

### Added
Expand Down
1 change: 1 addition & 0 deletions conan/profiles/release-clang-emscripten-wasm
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ os=Emscripten
build_type=Release
compiler=clang
compiler.version=14
compiler.cppstd=20
2 changes: 1 addition & 1 deletion emscripten/test_libqasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wrapper().then(function(result: any) {

try {
let output = cqasm.get_version()
let expected_output = "1.2.1"
let expected_output = "1.3.0"
console.log("\nThe version of libqasm compiled with emscripten is:", output);
if (output !== expected_output) {
console.log("\tExpected output:", expected_output)
Expand Down
2 changes: 2 additions & 0 deletions include/libqasm/v3x/instruction_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class InstructionSet {
[[nodiscard]] std::optional<std::string> get_non_gate_param_types(const std::string& name) const;
[[nodiscard]] std::optional<std::string> get_gate_modifier_param_types(const std::string& name) const;
[[nodiscard]] std::optional<std::string> get_instruction_param_types(const std::string& name) const;
[[nodiscard]] std::optional<std::string> get_non_gate_param_types_with_param_count(
const std::string& name, size_t param_count) const;
};

} // namespace cqasm::v3x::instruction
4 changes: 2 additions & 2 deletions include/libqasm/versioning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace cqasm {

static const char* version{ "1.2.1" };
static const char* release_year{ "2025" };
static const char* version{ "1.3.0" };
static const char* release_year{ "2026" };

[[nodiscard]] [[maybe_unused]] static const char* get_version() {
return version;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libqasm",
"version": "1.2.1",
"version": "1.3.0",
"repository": {
"type": "git",
"url": "https://github.com/QuTech-Delft/libqasm.git"
Expand Down
71 changes: 71 additions & 0 deletions res/v3x/tests/integration/instruction/U_param/ast.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
SUCCESS
Program(
version: <
Version( # input.cq:1:9..12
items: 3.0
)
>
block: <
GlobalBlock(
statements: [
Variable( # input.cq:3:7..8
name: <
Identifier(
name: q
)
>
typ: <
Type( # input.cq:3:1..6
name: <
Keyword(
name: qubit
)
>
size: -
)
>
annotations: []
)
GateInstruction( # input.cq:5:1..2
gate: <
Gate( # input.cq:5:1..2
name: <
Identifier(
name: U
)
>
gate: -
parameters: <
ExpressionList(
items: [
IntegerLiteral( # input.cq:5:3..4
value: 1
)
IntegerLiteral( # input.cq:5:5..6
value: 2
)
IntegerLiteral( # input.cq:5:7..8
value: 3
)
]
)
>
annotations: []
)
>
operands: <
ExpressionList(
items: [
Identifier( # input.cq:5:10..11
name: q
)
]
)
>
annotations: []
)
]
)
>
)

5 changes: 5 additions & 0 deletions res/v3x/tests/integration/instruction/U_param/input.cq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version 3.0

qubit q

U(1,2,3) q
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SUCCESS
Program(
api_version: 3.0
version: <
Version(
items: 3.0
)
>
block: <
Block(
statements: [
GateInstruction(
instruction_ref: U(qubit)
gate: <
Gate(
name: U
gate: -
parameters: [
ConstFloat(
value: 1
)
ConstFloat(
value: 2
)
ConstFloat(
value: 3
)
]
annotations: []
)
>
operands: [
VariableRef(
variable --> <
Variable(
name: q
typ: <
Qubit(
size: 1
)
>
annotations: []
)
>
)
]
annotations: []
)
]
)
>
variables: [
Variable(
name: q
typ: <
Qubit(
size: 1
)
>
annotations: []
)
]
)

7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def run(self):
with local.cwd(root_dir):
build_type = os.environ.get('CMAKE_BUILD_TYPE', 'Release')
build_tests = os.environ.get('LIBQASM_BUILD_TESTS', 'False')
# Optional Conan build patterns to force source builds (e.g. m4/flex/bison in manylinux).
extra_build_patterns = [
pattern for pattern in os.environ.get('LIBQASM_CONAN_BUILD_PATTERNS', '').split()
if pattern
]

cmd = local['conan']['profile']['detect']['--force']
cmd & FG
Expand All @@ -116,6 +121,8 @@ def run(self):
['-b']['missing']
['-tf']['']
)
for pattern in extra_build_patterns:
cmd = cmd['-b'][pattern]
if build_tests == 'True':
cmd = cmd['-c']['tools.build:skip_test=False']
if platform.system() == 'Darwin':
Expand Down
2 changes: 1 addition & 1 deletion src/v3x/CqasmParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ gate:
// Current implementation of the semantic parser will expect a constant integer
// for the first expression in the WAIT instruction
nonGateInstruction:
expression EQUALS MEASURE expression # measureInstruction
expression EQUALS MEASURE (OPEN_PARENS expressionList CLOSE_PARENS)? expression # measureInstruction
| RESET expression # resetInstruction
| INIT expression # initInstruction
| BARRIER expression # barrierInstruction
Expand Down
32 changes: 30 additions & 2 deletions src/v3x/instruction_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ InstructionSet::InstructionSet()
{ "mX90", { std::nullopt, "V" } },
{ "mY90", { std::nullopt, "Q" } },
{ "mY90", { std::nullopt, "V" } },
{ "mZ90", { std::nullopt, "Q" } },
{ "mZ90", { std::nullopt, "V" } },
{ "Rn", { "fffff", "Q" } },
{ "Rn", { "fffff", "V" } },
{ "Rx", { "f", "Q" } },
Expand All @@ -53,6 +55,8 @@ InstructionSet::InstructionSet()
{ "T", { std::nullopt, "V" } },
{ "Tdag", { std::nullopt, "Q" } },
{ "Tdag", { std::nullopt, "V" } },
{ "U", { "fff", "Q" } },
{ "U", { "fff", "V" } },
{ "X", { std::nullopt, "Q" } },
{ "X", { std::nullopt, "V" } },
{ "X90", { std::nullopt, "Q" } },
Expand All @@ -62,13 +66,19 @@ InstructionSet::InstructionSet()
{ "Y90", { std::nullopt, "Q" } },
{ "Y90", { std::nullopt, "V" } },
{ "Z", { std::nullopt, "Q" } },
{ "Z", { std::nullopt, "V" } }
{ "Z", { std::nullopt, "V" } },
{ "Z90", { std::nullopt, "Q" } },
{ "Z90", { std::nullopt, "V" } }
}
, non_gate_map{
{ "measure", { std::nullopt, "BQ" } },
{ "measure", { std::nullopt, "WV" } },
{ "measure", { std::nullopt, "BV" } },
{ "measure", { std::nullopt, "WQ" } },
{ "measure", { "fff", "BQ" } },
{ "measure", { "fff", "WV" } },
{ "measure", { "fff", "BV" } },
{ "measure", { "fff", "WQ" } },
{ "reset", { std::nullopt, "Q" } },
{ "reset", { std::nullopt, "V" } },
{ "init", { std::nullopt, "Q" } },
Expand All @@ -84,7 +94,7 @@ InstructionSet::InstructionSet()
{ "ctrl", std::nullopt },
}
, single_qubit_named_gate_list{
"H", "I", "mX90", "mY90", "Rn", "Rx", "Ry", "Rz", "S", "Sdag", "T", "Tdag", "X", "X90", "Y", "Y90", "Z"
"H", "I", "mX90", "mY90", "mZ90", "Rn", "Rx", "Ry", "Rz", "S", "Sdag", "T", "Tdag", "U", "X", "X90", "Y", "Y90", "Z", "Z90"
}
, two_qubit_named_gate_list{
"CNOT", "CR", "CRk", "CZ", "SWAP"
Expand Down Expand Up @@ -242,4 +252,22 @@ InstructionSet::InstructionSet()
throw error::AnalysisError{ fmt::format("couldn't find instruction '{}'", name) };
}

[[nodiscard]] std::optional<std::string> InstructionSet::get_non_gate_param_types_with_param_count(
const std::string& name, size_t param_count) const {
const auto& range = non_gate_map.equal_range(name);
for (auto it = range.first; it != range.second; ++it) {
const auto& param_types = it->second.first;
if (!param_types.has_value()) {
if (param_count == 0) {
return param_types;
}
} else {
if (param_types->size() == param_count) {
return param_types;
}
}
}
return std::nullopt;
}

} // namespace cqasm::v3x::instruction
32 changes: 32 additions & 0 deletions src/v3x/semantic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ bool is_two_qubit_gate(const tree::One<semantic::Gate>& gate) {
values::Values resolve_parameters(const std::string& instruction_name, const values::Values& parameters) {
auto ret = values::Values{};
const auto& instruction_set = InstructionSet::get_instance();

if (instruction_set.is_non_gate(instruction_name)) {
const auto& param_types =
instruction_set.get_non_gate_param_types_with_param_count(instruction_name, parameters.size());
bool found_with_zero_params = (!param_types.has_value() && parameters.empty());

if (!found_with_zero_params && !param_types.has_value()) {
throw error::AnalysisError{ fmt::format("instruction '{}' does not have an overload with {} parameters.",
instruction_name,
parameters.size()) };
}

if (found_with_zero_params) {
return ret;
} // No parameters expected, and none provided — return empty result

if (param_types.has_value()) {
std::for_each(param_types->begin(),
param_types->end(),
[i = 0, &instruction_name, &parameters, &ret](const auto& param_type) mutable {
if (!values::check_promote(values::type_of(parameters[i]), types::from_spec(param_type))) {
throw error::AnalysisError{ fmt::format("failed to resolve '{}' with parameter type ({})",
instruction_name,
values::type_of(parameters[i])) };
}
ret.add(promote(parameters[i], types::from_spec(param_type)));
i++;
});
}
return ret;
}

const auto& param_types = instruction_set.get_instruction_param_types(instruction_name);
if (!param_types.has_value()) {
if (!parameters.empty()) {
Expand Down
4 changes: 3 additions & 1 deletion src/v3x/syntactic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ std::any SyntacticAnalyzer::visitNamedGate(CqasmParser::NamedGateContext* contex
std::any SyntacticAnalyzer::visitMeasureInstruction(CqasmParser::MeasureInstructionContext* context) {
auto ret = tree::make<NonGateInstruction>();
ret->name = tree::make<Keyword>(context->MEASURE()->getText());
ret->parameters = tree::make<ExpressionList>();
ret->parameters = context->expressionList()
? std::any_cast<One<ExpressionList>>(visitExpressionList(context->expressionList()))
: tree::make<ExpressionList>();
ret->operands = tree::make<ExpressionList>();
ret->operands->items.add(std::any_cast<One<Expression>>(context->expression(0)->accept(this)));
ret->operands->items.add(std::any_cast<One<Expression>>(context->expression(1)->accept(this)));
Expand Down
Loading
Loading