Skip to content

Commit

Permalink
New 3-qubit and 4-qubit Gates (#592)
Browse files Browse the repository at this point in the history
* temp commit

* moved to new file

* first tests

* mqg test fixes

* prelude OperateFourQubit

* four_qubit_gate_op file mod

* tests mod

* involv qubits

* lib OperateFourQubit

* substitute control_2

* finished testing cccx

* circuits

* again circuits

* tests

* operate enum four + three fix

* missed build.rs stuff (enum)

* OperateFourQubitGate

* JsonSchema test

* doctests fix

* newline

* feature gate

* missed qoqo build.rs

* mod qoqo

* lib qoqo-macro

* interface

* interface tests

* fmt

* CHANGELOG

* json_schema fix

* compat tests

* lock

* qoqo

* macros

* derive

* test

* roqoqo

* changelog

* build.rs roq

* ops mod roq

* copyright

* lock

* DEP

* fixed changelog

* again fix

* cswap definitions

* cswap tests

* qoqo-macros new targets-controls

* prelude

* OperateThreeQubit new sol

* involvequbits new targets-controls

* again

* operate n qubits new targets-controls

* substitute

* test fix

* lock

* doc fix

* changelog

* triplecontrolledphaseshift definitions

* changelog

* triplecontrolledphaseshift tests

* phase-shifted changelog

* roq derive sol (to be changed)

* phase-shifted double-controlled definitions

* phse-shifted double-controlled tests

* roq derive incompatibility fix (wip qoqo)

* better docs

* qoqo compatiiblity issue cswap fix

* fmt

* qoqo mod

* redundant changlog

* clippy

* dereference

* pr corrections

* misisng tests

* small derive fixes

* no target_0 target_1 reserved fields
  • Loading branch information
mlodi-hqs authored Oct 17, 2024
1 parent 537fd05 commit 2aef56c
Show file tree
Hide file tree
Showing 25 changed files with 4,120 additions and 27 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

This changelog track changes to the qoqo project starting at version v0.5.0


## 1.16.0

### Fixed in 1.16.0
Expand All @@ -11,7 +10,7 @@ This changelog track changes to the qoqo project starting at version v0.5.0

### Added in 1.16.0

* Added `InvSGate`, `InvTGate`, `SXGate`, `InvSXGate` gates.
* Added `InvSGate`, `InvTGate`, `SXGate`, `InvSXGate`, `TripleControlledPauliX`, `TripleControlledPauliZ`, `TripleControlledPhaseShift`, `ControlledSWAP`, `PhaseShiftedControlledControlledZ`, `PhaseShiftedControlledControlledPhase` gates.

## 1.15.2

Expand Down Expand Up @@ -39,7 +38,7 @@ This changelog track changes to the qoqo project starting at version v0.5.0

### Added in 1.15.0

* Added `SqrtPaulY` and `InvSqrtPauliY` gates.
* Added `SqrtPauliY` and `InvSqrtPauliY` gates.

## 1.14.0

Expand Down
40 changes: 39 additions & 1 deletion qoqo-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ pub fn devicechainenvironmentwrapper(
}

/// Array of field names that are reserved for use with specific traits
const RESERVED_FIELDS: &[&str; 15] = &[
const RESERVED_FIELDS: &[&str; 16] = &[
"qubit",
"control",
"control_0",
"control_1",
"control_2",
"target",
"qubits",
"global_phase",
Expand Down Expand Up @@ -368,6 +369,41 @@ pub fn wrap(
} else {
TokenStream::new()
};
let operate_four_qubit_quote = if attribute_arguments.contains("OperateFourQubit") {
quote! {
/// Returns control_0 qubit of the four-qubit operation
pub fn control_0(&self) -> usize {
self.internal.control_0().clone()
}
/// Returns control_1 qubit of the four-qubit operation
pub fn control_1(&self) -> usize {
self.internal.control_1().clone()
}
/// Returns control_2 qubit of the four-qubit operation
pub fn control_2(&self) -> usize {
self.internal.control_2().clone()
}
/// Returns target qubit of the four-qubit operation
pub fn target(&self) -> usize {
self.internal.target().clone()
}
}
} else {
TokenStream::new()
};
let operate_four_qubit_gate_quote = if attribute_arguments.contains("OperateFourQubitGate") {
quote! {
/// Returns circuit implementing the FourQubitGateOperation
///
/// Returns:
/// Circuit
pub fn circuit(&self) -> CircuitWrapper {
CircuitWrapper { internal: self.internal.circuit().clone() }
}
}
} else {
TokenStream::new()
};
let operate_gate_quote = if attribute_arguments.contains("OperateGate") {
quote! {
/// Return unitary matrix of gate.
Expand Down Expand Up @@ -623,6 +659,8 @@ pub fn wrap(
// #operate_two_qubit_gate_quote
#operate_three_qubit_quote
#operate_three_qubit_gate_quote
#operate_four_qubit_quote
#operate_four_qubit_gate_quote
#operate_multi_qubit_quote
#operate_multi_qubit_gate_quote
#operate_gate_quote
Expand Down
1 change: 1 addition & 0 deletions qoqo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const SOURCE_FILES: &[&str] = &[
"src/operations/pragma_operations.rs",
"src/operations/two_qubit_gate_operations.rs",
"src/operations/three_qubit_gate_operations.rs",
"src/operations/four_qubit_gate_operations.rs",
"src/operations/multi_qubit_gate_operations.rs",
"src/operations/measurement_operations.rs",
"src/operations/define_operations.rs",
Expand Down
81 changes: 81 additions & 0 deletions qoqo/src/operations/four_qubit_gate_operations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright © 2021-2024 HQS Quantum Simulations GmbH. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing permissions and
// limitations under the License.

use num_complex::Complex64;
use numpy::{PyArray2, ToPyArray};

use qoqo_calculator::CalculatorFloat;
use qoqo_calculator_pyo3::{convert_into_calculator_float, CalculatorFloatWrapper};

use crate::CircuitWrapper;

use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::PySet;

use std::collections::HashMap;

#[cfg(feature = "json_schema")]
use roqoqo::ROQOQO_VERSION;

use roqoqo::operations::*;

use qoqo_macros::*;

#[wrap(
Operate,
OperateFourQubit,
OperateGate,
OperateFourQubitGate,
JsonSchema
)]
/// The triple-controlled PauliX gate.
///
pub struct TripleControlledPauliX {
control_0: usize,
control_1: usize,
control_2: usize,
target: usize,
}

#[wrap(
Operate,
OperateFourQubit,
OperateGate,
OperateFourQubitGate,
JsonSchema
)]
/// The triple-controlled PauliZ gate.
///
pub struct TripleControlledPauliZ {
control_0: usize,
control_1: usize,
control_2: usize,
target: usize,
}

#[wrap(
Operate,
OperateFourQubit,
OperateGate,
OperateFourQubitGate,
JsonSchema
)]
/// The triple-controlled PhaseShift gate.
///
pub struct TripleControlledPhaseShift {
control_0: usize,
control_1: usize,
control_2: usize,
target: usize,
theta: CalculatorFloat,
}
8 changes: 8 additions & 0 deletions qoqo/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ mod two_qubit_gate_operations;
pub use two_qubit_gate_operations::*;
mod three_qubit_gate_operations;
pub use three_qubit_gate_operations::*;
mod four_qubit_gate_operations;
pub use four_qubit_gate_operations::*;
mod multi_qubit_gate_operations;
pub use multi_qubit_gate_operations::*;
mod bosonic_operations;
Expand Down Expand Up @@ -190,6 +192,12 @@ pub fn operations(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<InvTGateWrapper>()?;
m.add_class::<SXGateWrapper>()?;
m.add_class::<InvSXGateWrapper>()?;
m.add_class::<TripleControlledPauliXWrapper>()?;
m.add_class::<TripleControlledPauliZWrapper>()?;
m.add_class::<TripleControlledPhaseShiftWrapper>()?;
m.add_class::<ControlledSWAPWrapper>()?;
m.add_class::<PhaseShiftedControlledControlledZWrapper>()?;
m.add_class::<PhaseShiftedControlledControlledPhaseWrapper>()?;

Ok(())
}
Loading

0 comments on commit 2aef56c

Please sign in to comment.