Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #73 from danbev/add-pretty-matrix
Browse files Browse the repository at this point in the history
add prettyMatrix method to Gate class
  • Loading branch information
jesusprubio authored May 22, 2019
2 parents fcef410 + 063e716 commit e474949
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `@qiskit/qiskit-qasm`: Use QasmError for jison error handling
- `@qiskit/qiskit-qasm`: Make parser a member of class Parser
- `@qiskit/qiskit-qasm`: Use TypeError as error for incorrect type
- `@qiskit/qiskit-sim`: add prettyMatrix method to Gate class

## [0.9.0] - 2019-05-13

Expand Down
6 changes: 6 additions & 0 deletions packages/qiskit-sim/lib/gates.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Gate {
this.name = name;
this.matrix = matrix;
}

prettyMatrix() {
let str = '';
this.matrix.forEach( (m) => { str += `[${m.join(', ')}]\n`; } );
return str;
}
}

Gate.x = new Gate('x', [[0, 1], [1, 0]]);
Expand Down
8 changes: 8 additions & 0 deletions packages/qiskit-sim/test/functional/gates.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ describe('sim:gates', () => {
it('t gate should have the same unitary matrix as the r4 gate', () => {
assert.deepEqual(Gate.t.matrix, Gate.r4.matrix);
});

it('prettyMatrix should return a pretty matrix', () => {
const expected = '[1, 0, 0, 0]\n' +
'[0, 1, 0, 0]\n' +
'[0, 0, 0, 1]\n' +
'[0, 0, 1, 0]\n';
assert.strictEqual(Gate.cx.prettyMatrix(), expected);
});
});

0 comments on commit e474949

Please sign in to comment.