Skip to content

Commit

Permalink
Filter U gate from output of SymbolTable::gates
Browse files Browse the repository at this point in the history
The Qiskit importer otherwise needs to filter this gate out.
Other consumers probably would do so as well. If it is useful in
antother context, we can add an option to include the U gate

Review comment: Qiskit/qiskit#12087 (comment)
  • Loading branch information
jlapeyre committed May 2, 2024
1 parent 5162cf8 commit fc8dfa7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/oq3_semantics/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,19 @@ impl SymbolTable {

/// Return a Vec of information about all gate declarations. Each element
/// is a tuple of (gate name, symbol id, num classical params, num quantum params).
/// `gphase` is not included here. It is treated specially.
/// `U` is also filtered out, as it is builtin.
pub fn gates(&self) -> Vec<(&str, SymbolId, usize, usize)> {
self.all_symbols
.iter()
.enumerate()
.filter_map(|(n, sym)| {
if let Type::Gate(num_cl, num_qu) = &sym.symbol_type() {
Some((sym.name(), SymbolId(n), *num_cl, *num_qu))
if sym.name() == "U" {
None
} else {
Some((sym.name(), SymbolId(n), *num_cl, *num_qu))
}
} else {
None
}
Expand Down

0 comments on commit fc8dfa7

Please sign in to comment.