Skip to content

Commit

Permalink
rename ops to *halfturns
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed Sep 16, 2024
1 parent 131ed11 commit bb769ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tket2-hseries/src/extension/hseries/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn op_to_hugr(op: Tk2Op) -> Result<Hugr, LowerTk2Error> {
}

fn build_to_radians(b: &mut DFGBuilder<Hugr>, rotation: Wire) -> Result<Wire, BuildError> {
let turns = b.add_toturns(rotation)?;
let turns = b.add_to_halfturns(rotation)?;
let pi = pi_mul_f64(b, 1.0);
let float = b.add_dataflow_op(FloatOps::fmul, [turns, pi])?.out_wire(0);
Ok(float)
Expand Down
32 changes: 16 additions & 16 deletions tket2/src/extension/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ impl CustomConst for ConstRotation {
#[non_exhaustive]
/// Rotation operations
pub enum RotationOp {
/// Construct rotation from number of half turns (would be multiples of π in radians).
fromturns,
/// Convert rotation to number of half turns (would be multiples of π in radians).
toturns,
/// Construct rotation from number of half-turns (would be multiples of π in radians).
from_halfturns,
/// Convert rotation to number of half-turns (would be multiples of π in radians).
to_halfturns,
/// Add two angles together (experimental, may be removed, use float addition
/// first instead if possible).
radd,
Expand All @@ -131,11 +131,11 @@ impl MakeOpDef for RotationOp {

fn signature(&self) -> hugr::extension::SignatureFunc {
match self {
RotationOp::fromturns => Signature::new(
RotationOp::from_halfturns => Signature::new(
type_row![FLOAT64_TYPE],
Type::from(option_type(type_row![ROTATION_TYPE])),
),
RotationOp::toturns => {
RotationOp::to_halfturns => {
Signature::new(type_row![ROTATION_TYPE], type_row![FLOAT64_TYPE])
}
RotationOp::radd => Signature::new(
Expand All @@ -148,11 +148,11 @@ impl MakeOpDef for RotationOp {

fn description(&self) -> String {
match self {
RotationOp::fromturns => {
"Construct rotation from number of turns (would be multiples of π in radians)."
RotationOp::from_halfturns => {
"Construct rotation from number of half-turns (would be multiples of π in radians)."
}
RotationOp::toturns => {
"Convert rotation to number of turns (would be multiples of π in radians)."
RotationOp::to_halfturns => {
"Convert rotation to number of half-turns (would be multiples of π in radians)."
}
RotationOp::radd => "Add two angles together (experimental).",
}
Expand Down Expand Up @@ -194,16 +194,16 @@ pub(super) fn add_to_extension(extension: &mut Extension) {
/// "tket2.rotation" operations.
pub trait RotationOpBuilder: Dataflow {
/// Add a "tket2.rotation.fromturns" op.
fn add_fromturns(&mut self, turns: Wire) -> Result<Wire, BuildError> {
fn add_from_halfturns(&mut self, turns: Wire) -> Result<Wire, BuildError> {
Ok(self
.add_dataflow_op(RotationOp::fromturns, [turns])?
.add_dataflow_op(RotationOp::from_halfturns, [turns])?
.out_wire(0))
}

/// Add a "tket2.rotation.toturns" op.
fn add_toturns(&mut self, rotation: Wire) -> Result<Wire, BuildError> {
fn add_to_halfturns(&mut self, rotation: Wire) -> Result<Wire, BuildError> {
Ok(self
.add_dataflow_op(RotationOp::toturns, [rotation])?
.add_dataflow_op(RotationOp::to_halfturns, [rotation])?
.out_wire(0))
}
}
Expand Down Expand Up @@ -267,8 +267,8 @@ mod test {
.unwrap();

let [rotation] = builder.input_wires_arr();
let turns = builder.add_toturns(rotation).unwrap();
let mb_rotation = builder.add_fromturns(turns).unwrap();
let turns = builder.add_to_halfturns(rotation).unwrap();
let mb_rotation = builder.add_from_halfturns(turns).unwrap();
let _hugr = builder
.finish_hugr_with_outputs([mb_rotation], &REGISTRY)
.unwrap();
Expand Down

0 comments on commit bb769ba

Please sign in to comment.