Skip to content

[bug] Fix MacOS compilation and implicit conversion in to_qasm()#229

Merged
xumingkuan merged 4 commits intomasterfrom
pengyu_fix_compilation
Nov 21, 2025
Merged

[bug] Fix MacOS compilation and implicit conversion in to_qasm()#229
xumingkuan merged 4 commits intomasterfrom
pengyu_fix_compilation

Conversation

@liupengy19
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings November 21, 2025 21:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses compilation issues related to C++17 standard compliance and macOS SDK configuration. The changes ensure the codebase compiles correctly by explicitly setting the C++17 standard flag and adding macOS-specific SDK paths. Additionally, string literals passed to the to_qasm function are wrapped with std::string() constructors, though this appears unnecessary given the function signature accepts const std::string&.

Key changes:

  • Explicitly added -std=c++17 flag to CMAKE_CXX_FLAGS for non-MSVC builds
  • Added macOS SDK path configuration using xcrun and isysroot flags
  • Wrapped string literal arguments to Graph::to_qasm() calls with explicit std::string() constructors in test files

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
CMakeLists.txt Added -std=c++17 flag and macOS SDK path configuration for compilation
src/test/test_rigetti_td_disabled.cpp Wrapped string literal in std::string() constructor for to_qasm() call
src/test/test_graph_to_qasm.cpp Wrapped string literal in std::string() constructor for to_qasm() call
src/test/test_from_and_to_qasm.cpp Wrapped string literal in std::string() constructor for to_qasm() call
src/test/test_apply_xfer.cpp Wrapped string literal in std::string() constructor for to_qasm() call
.gitignore Added .cache/ directory to gitignore

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


Graph graph(&ctx, dag);
graph.to_qasm("temp.qasm", /*print_result=*/true, true);
graph.to_qasm(std::string("temp.qasm"), /*print_result=*/true, true);
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::string() wrapper on line 20 is inconsistent with line 21 where draw_circuit (which also accepts const std::string& parameters) is called with string literals directly. Since to_qasm accepts const std::string&, the explicit wrapper is unnecessary - string literals implicitly convert to std::string. Consider removing the wrapper for consistency: graph.to_qasm("temp.qasm", /*print_result=*/true, true);

Suggested change
graph.to_qasm(std::string("temp.qasm"), /*print_result=*/true, true);
graph.to_qasm("temp.qasm", /*print_result=*/true, true);

Copilot uses AI. Check for mistakes.
true);
graph_after_h_cz_merge->to_qasm(
"circuit/voqc-benchmarks/after_h_cz_merge.qasm", false, false);
std::string("circuit/voqc-benchmarks/after_h_cz_merge.qasm"), false,
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::string() wrapper is inconsistent with line 114 in the same file where to_qasm(output_fn, false, false) is called without wrapping. Since the function signature is void to_qasm(const std::string &save_filename, bool print_result, bool print_guid), string literals implicitly convert to const std::string&. Consider removing the wrapper for consistency: graph_after_h_cz_merge->to_qasm("circuit/voqc-benchmarks/after_h_cz_merge.qasm", false, false);

Suggested change
std::string("circuit/voqc-benchmarks/after_h_cz_merge.qasm"), false,
"circuit/voqc-benchmarks/after_h_cz_merge.qasm", false,

Copilot uses AI. Check for mistakes.
auto graph =
Graph::from_qasm_file(&ctx, "../experiment/nam_rm_circs/gf2^6_mult.qasm");
graph->to_qasm("test.qasm", false, false);
graph->to_qasm(std::string("test.qasm"), false, false);
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::string() wrapper is unnecessary since to_qasm accepts const std::string& which allows implicit conversion from string literals. This is inconsistent with other test files like test_rotation_merging.cpp and test_toffoli_flip.cpp where variables of type std::string are passed directly. Consider using the literal directly: graph->to_qasm("test.qasm", false, false);

Suggested change
graph->to_qasm(std::string("test.qasm"), false, false);
graph->to_qasm("test.qasm", false, false);

Copilot uses AI. Check for mistakes.
}

best_graph->to_qasm("test.qasm", false, false);
best_graph->to_qasm(std::string("test.qasm"), false, false);
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::string() wrapper is unnecessary since to_qasm accepts const std::string& which allows implicit conversion from string literals. This is inconsistent with similar calls in other test files. Consider using the literal directly: best_graph->to_qasm("test.qasm", false, false);

Suggested change
best_graph->to_qasm(std::string("test.qasm"), false, false);
best_graph->to_qasm("test.qasm", false, false);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@xumingkuan xumingkuan changed the title Fix multiple problems doing compilation [bug] Fix MacOS compilation and implicit conversion in to_qasm() Nov 21, 2025
@xumingkuan xumingkuan merged commit b367e34 into master Nov 21, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants